Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/server/fs/lib/Resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2012-2015 S-Core Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Resource class representing a resource(file, dir) in Webida FS
* @class
*/

'use strict';

var Path = require('path');
var URI = require('URIjs');
var WebidaFS = require('./webidafs').WebidaFS;

function Resource(wfsUrl) {
this.uri = URI(wfsUrl);
this.fsid = this.uri.host();
this.wfs = new WebidaFS(this.fsid);
this.pathname = decodeURI(this.uri.pathname());
this.basename = Path.basename(this.pathname);
this.localPath = this.wfs.getFSPath(this.pathname);
}

Resource.prototype.equals = function (rsc2) {
return this.uri.equals(rsc2.uri);
};

Resource.prototype.getParent = function () {
var parentResource;
var parentUri = this.uri.clone();
parentUri.pathname(Path.dirname(this.uri.pathname()));
parentResource = new Resource(parentUri);
if (parentResource.equals(this)) {
return null;
}
return parentResource;
};

module.exports = Resource;
27 changes: 14 additions & 13 deletions src/server/fs/lib/console-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

var childProc = require('child_process');
var fsMgr = require('./fs-manager');
var Resource = fsMgr.Resource;
var Resource = require('./Resource');
var ptyjs = require('pty.js');
var path = require('path');
var _ = require('lodash');
Expand Down Expand Up @@ -123,7 +123,7 @@ function startProc(cwdRsc, cexec, callback) {
});

proc.on('exit', function (code) {
logger.debug('Exec close', proc.pid, 'code:'+code, 'stdout:'+proc._stdout, 'stderr:'+proc._stderr);
logger.debug('Exec close', proc.pid, 'code:' + code, 'stdout:' + proc._stdout, 'stderr:' + proc._stderr);
removeProc(proc);
if (code === null) {
return callback(new Error('Abnormal exit'), proc._stdout, proc._stderr);
Expand Down Expand Up @@ -210,7 +210,7 @@ function handleNewEvent(socket, options, cb) {
pid = pty.pid;
addProc(pty, cexec, false);

socket.on('data', function(data) {
socket.on('data', function (data) {
pty.write(data);
});

Expand Down Expand Up @@ -239,10 +239,11 @@ function handleNewEvent(socket, options, cb) {
var cmd;
var cpid;
var STATE = Object.freeze({
SEARCH:0,
NEWLINE:1,
CPID:2,
DONE:3});
SEARCH: 0,
NEWLINE: 1,
CPID: 2,
DONE: 3
});
var state = STATE.SEARCH;

if (!cwd) {
Expand All @@ -258,7 +259,7 @@ function handleNewEvent(socket, options, cb) {

pty.pause();
pty.write(cmd);
var dropMsg = function() {
var dropMsg = function () {
/* accumulate all data from lxc */
var c;
while (null !== (c = pty.socket.read())) {
Expand Down Expand Up @@ -300,7 +301,7 @@ function handleNewEvent(socket, options, cb) {
} else {
/* bind to client */
logger.debug('bind terminal to client');
pty.on('data', function(data) {
pty.on('data', function (data) {
socket.emit('data', data);
});
cb();
Expand Down Expand Up @@ -356,7 +357,7 @@ exports.router.post('/webida/api/fs/exec/:fsid/*',
authMgr.ensureLogin,
function (req, res, next) {
var rsc = 'fs:' + req.params.fsid + '/*';
authMgr.checkAuthorize({uid:req.user.uid, action:'fs:exec', rsc:rsc}, res, next);
authMgr.checkAuthorize({uid: req.user.uid, action: 'fs:exec', rsc: rsc}, res, next);
},
utils.keepConnect(),
function (req, res) {
Expand All @@ -371,7 +372,7 @@ exports.router.post('/webida/api/fs/exec/:fsid/*',
}

logger.debug('exec path=' + cwdPath, cmdInfo);
fsMgr.checkLock(fsid, cwdPath, cmdInfo, function(err) {
fsMgr.checkLock(fsid, cwdPath, cmdInfo, function (err) {
if (err) {
return res.sendfail(err);
}
Expand All @@ -380,9 +381,9 @@ exports.router.post('/webida/api/fs/exec/:fsid/*',
if (err) {
return res.sendfail(err);
}
fsMgr.updateByExec(cmdInfo,uid, fsid, cwdPath, cwdUrl, sessionID, function() {
fsMgr.updateByExec(cmdInfo, uid, fsid, cwdPath, cwdUrl, sessionID, function () {
logger.debug('exec notification done');
return res.sendok({stdout: stdout, stderr: stderr, ret:ret});
return res.sendok({stdout: stdout, stderr: stderr, ret: ret});
});
});
});
Expand Down
Loading