mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) add ability to show progress on move (#157)
This commit is contained in:
parent
c793082ec8
commit
697df5846f
4 changed files with 20 additions and 46 deletions
|
|
@ -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,18 @@ function onPUT(name, body, callback) {
|
|||
const to = root(files.to);
|
||||
const names = files.names;
|
||||
|
||||
moveFiles({from, to, names}, fn);
|
||||
if (names)
|
||||
return moveFiles(from, to, names)
|
||||
.on('error', fn)
|
||||
.on('end', fn);
|
||||
|
||||
const dirname = path.dirname;
|
||||
const basename = path.basename;
|
||||
|
||||
moveFiles(dirname(from), dirname(to), [basename(to)])
|
||||
.on('error', fn)
|
||||
.on('end', fn);
|
||||
|
||||
break;
|
||||
} case 'cp':
|
||||
if (!files.from || !files.names || !files.to)
|
||||
|
|
|
|||
|
|
@ -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!');
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue