diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index db2e10f194..20cd77c013 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -118,6 +118,11 @@ function OperationProto(operation, data) { .then(setListeners(callback)); }; + moveFn = (data, callback) => { + operator.move(data.from, data.to, data.names) + .then(setListeners(callback)); + }; + extractFn = (data, callback) => { operator.extract(data.from, data.to) .then(setListeners({noContinue: true}, callback)); diff --git a/package.json b/package.json index b4a8d84610..3158e09cbc 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,8 @@ }, "subdomain": "cloudcmd", "dependencies": { - "@cloudcmd/fileop": "^1.0.1", + "@cloudcmd/fileop": "^1.1.0", + "@cloudcmd/move-files": "^1.0.0", "@cloudcmd/read-files-sync": "^1.0.0", "apart": "^1.0.1", "chalk": "^2.0.1", diff --git a/server/rest/index.js b/server/rest/index.js index 11043acd64..f56430a1c6 100644 --- a/server/rest/index.js +++ b/server/rest/index.js @@ -18,7 +18,7 @@ const json = require('jonny/legacy'); const ponse = require('ponse'); const copymitter = require('copymitter'); -const moveFiles = require('./move-files'); +const moveFiles = require('@cloudcmd/move-files'); const swap = wraptile((fn, a, b) => fn(b, a)); const isWin32 = process.platform === 'win32'; @@ -182,7 +182,9 @@ function onPUT(name, body, callback) { const to = root(files.to); const names = files.names; - moveFiles({from, to, names}, fn); + moveFiles(from, to, names) + .on('error', fn) + .on('end', fn); break; } case 'cp': if (!files.from || !files.names || !files.to) diff --git a/server/rest/move-files.js b/server/rest/move-files.js deleted file mode 100644 index bcb5883bf1..0000000000 --- a/server/rest/move-files.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -const path = require('path'); -const flop = require('flop'); -const promisify = require('es6-promisify').promisify; - -const move = promisify(flop.move); - -module.exports = (files, callback) => { - check(files, callback); - - if (!files.names) - return move(files.from, files.to) - .then(callback) - .catch(callback); - - const names = files.names.slice(); - const iterate = () => { - const isLast = !names.length; - - if (isLast) - return callback(); - - const name = names.shift(); - const from = path.join(files.from, name); - const to = path.join(files.to, name); - - move(from, to) - .then(iterate) - .catch(callback); - }; - - iterate(); -}; - -function check(files, callback) { - if (typeof files !== 'object') - throw Error('files should be an object!'); - - if (typeof callback !== 'function') - throw Error('callback should be a function!'); -} -