From d2908cc08d21b675c10cec0a68f6e03378711da8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 8 Jul 2014 10:22:17 -0400 Subject: [PATCH] refactor(win) mv isVolume, isChangeVolume --- lib/server/console.js | 31 ++++++------------------------- lib/server/win.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/server/console.js b/lib/server/console.js index 4caf5ce4..d1991d1d 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -5,6 +5,9 @@ socket = main.socket, update = main.srvrequire('update'), + DIR = '../', + DIR_SERVER = './', + win = require(DIR_SERVER + 'win'), exec = main.child_process.exec, spawn = main.child_process.spawn, @@ -97,7 +100,7 @@ var funcExec, firstChar, connName, ret, isContain, - isVolume = isChangeWinVolume(command), + isVolume = win.isChangeVolume(command), symbolsExec = ['*', '&', '{', '}', '|', '\'', '"'], CWD = process.cwd(), @@ -265,8 +268,8 @@ } function onCD(command, currDir, callback) { - var isChangeVolume = isChangeWinVolume(command), - isVolume = isWinVolume(command), + var isChangeVolume = win.isChangeVolume(command), + isVolume = win.isVolume(command), paramDir = Util.rmStr(command, 'cd '), isRootOrHome = equalPart(paramDir, ['/', '~']), getDir = WIN32 ? 'chdir' : 'pwd'; @@ -291,28 +294,6 @@ }); } - function isWinVolume(command) { - var is, winVolume; - - if (WIN32) { - winVolume = new RegExp('^[a-z]{1}:\\\\.*', 'i'); - is = command.match(winVolume); - } - - return is; - } - - function isChangeWinVolume(command) { - var is, winVolume; - - if (WIN32) { - winVolume = new RegExp('^[a-z]{1}:$', 'i'); - is = command.match(winVolume); - } - - return is; - } - function log(connNum, str, typeParam) { var ret, type = ' '; diff --git a/lib/server/win.js b/lib/server/win.js index ca503882..3a559d1b 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -18,11 +18,17 @@ DIR = '../', DIR_SERVER = DIR + 'server/', Util = require(DIR + 'util'), - pipe = require(DIR_SERVER + 'pipe'); + pipe = require(DIR_SERVER + 'pipe'), + + WIN = process.platform === 'win32', + WIN_VOLUME = '^[a-z]{1}:$'; exports.getVolumes = getVolumes; exports.prepareCodePage = prepareCodePage; + exports.isVolume = isVolume; + exports.isChangeVolume = isChangeVolume; + function getVolumes(callback) { var wmic = spawn('wmic', ['logicaldisk', 'get', 'name']); @@ -98,4 +104,30 @@ }); } + function isVolume(command) { + var is, winVolume; + + Util.checkArgs(arguments, ['command']); + + if (WIN) { + winVolume = new RegExp(WIN_VOLUME + '\\\\.*', 'i'); + is = command.match(winVolume); + } + + return is; + } + + function isChangeVolume(command) { + var is, winVolume; + + Util.checkArgs(arguments, ['command']); + + if (WIN) { + winVolume = new RegExp(WIN_VOLUME, 'i'); + is = command.match(winVolume); + } + + return is; + } + })();