diff --git a/ChangeLog b/ChangeLog index f8aa55c2..9c2f56d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -106,6 +106,8 @@ getJSONfromFileTable. * feature(util) add logArray +* feature(socket) add chdir on cd + 2012.04.22, v0.2.0 diff --git a/lib/server/socket.js b/lib/server/socket.js index 400d454c..c61731f9 100644 --- a/lib/server/socket.js +++ b/lib/server/socket.js @@ -95,7 +95,8 @@ */ function onMessage(pConnNum, pSocket){ return function(pCommand) { - var lMsg, lWinCommand, lExec_func; + var lMsg, lJSON, lWinCommand, lExec_func, lDir, + lHome, lError; Util.log('#' + pConnNum + ': ' + pCommand); @@ -115,20 +116,38 @@ pCommand = 'kill -9 ' + process.pid; } else { - lMsg = { + lJSON = { stdout : CLOUDCMD + ' exit \n' + CLOUDCMD + ' update \n', stderr : null }; - lMsg = JSON.stringify(lMsg); + lMsg = Util.stringifyJSON( lJSON ); pSocket.send(lMsg); Util.log('received from client: ' + pCommand); Util.log('sended to client: ' + lMsg); } } else if( Util.isContainStrAtBegin(pCommand, 'cd ') ) { - pCommand = Util.removeStr(pCommand, 'cd '); + lDir = Util.removeStr(pCommand, 'cd '); + lHome = process.env.HOME; + + if ( Util.isContainStr(lDir, '~') ) + lDir = Util.replaceStr(lDir, '~', lHome); + + lError = Util.tryCatchLog(function(){ + process.chdir(lDir); + }); + + if (lError) { + lJSON = { + stderr: Util.stringifyJSON( lError ) + }; + + lMsg = Util.stringifyJSON( lJSON ); + + pSocket.send(lMsg); + } } /* if we on windows and command is build in