mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 04:37:12 +02:00
Pardon the noise. More tab to space conversion!
This commit is contained in:
parent
c3635bb26b
commit
1d8be6b014
128 changed files with 8017 additions and 8017 deletions
|
@ -1,28 +1,28 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const EnigAssert = require('./enigma_assert.js');
|
||||
// ENiGMA½
|
||||
const EnigAssert = require('./enigma_assert.js');
|
||||
|
||||
// deps
|
||||
const fse = require('fs-extra');
|
||||
const paths = require('path');
|
||||
const async = require('async');
|
||||
// deps
|
||||
const fse = require('fs-extra');
|
||||
const paths = require('path');
|
||||
const async = require('async');
|
||||
|
||||
exports.moveFileWithCollisionHandling = moveFileWithCollisionHandling;
|
||||
exports.copyFileWithCollisionHandling = copyFileWithCollisionHandling;
|
||||
exports.pathWithTerminatingSeparator = pathWithTerminatingSeparator;
|
||||
exports.moveFileWithCollisionHandling = moveFileWithCollisionHandling;
|
||||
exports.copyFileWithCollisionHandling = copyFileWithCollisionHandling;
|
||||
exports.pathWithTerminatingSeparator = pathWithTerminatingSeparator;
|
||||
|
||||
function moveOrCopyFileWithCollisionHandling(src, dst, operation, cb) {
|
||||
operation = operation || 'copy';
|
||||
const dstPath = paths.dirname(dst);
|
||||
const dstFileExt = paths.extname(dst);
|
||||
const dstFileSuffix = paths.basename(dst, dstFileExt);
|
||||
operation = operation || 'copy';
|
||||
const dstPath = paths.dirname(dst);
|
||||
const dstFileExt = paths.extname(dst);
|
||||
const dstFileSuffix = paths.basename(dst, dstFileExt);
|
||||
|
||||
EnigAssert('move' === operation || 'copy' === operation);
|
||||
|
||||
let renameIndex = 0;
|
||||
let opOk = false;
|
||||
let renameIndex = 0;
|
||||
let opOk = false;
|
||||
let tryDstPath;
|
||||
|
||||
function tryOperation(src, dst, callback) {
|
||||
|
@ -38,10 +38,10 @@ function moveOrCopyFileWithCollisionHandling(src, dst, operation, cb) {
|
|||
}
|
||||
|
||||
async.until(
|
||||
() => opOk, // until moved OK
|
||||
() => opOk, // until moved OK
|
||||
(cb) => {
|
||||
if(0 === renameIndex) {
|
||||
// try originally supplied path first
|
||||
// try originally supplied path first
|
||||
tryDstPath = dst;
|
||||
} else {
|
||||
tryDstPath = paths.join(dstPath, `${dstFileSuffix}(${renameIndex})${dstFileExt}`);
|
||||
|
@ -49,11 +49,11 @@ function moveOrCopyFileWithCollisionHandling(src, dst, operation, cb) {
|
|||
|
||||
tryOperation(src, tryDstPath, err => {
|
||||
if(err) {
|
||||
// for some reason fs-extra copy doesn't pass err.code
|
||||
// :TODO: this is dangerous: submit a PR to fs-extra to set EEXIST
|
||||
// for some reason fs-extra copy doesn't pass err.code
|
||||
// :TODO: this is dangerous: submit a PR to fs-extra to set EEXIST
|
||||
if('EEXIST' === err.code || 'copy' === operation) {
|
||||
renameIndex += 1;
|
||||
return cb(null); // keep trying
|
||||
return cb(null); // keep trying
|
||||
}
|
||||
|
||||
return cb(err);
|
||||
|
@ -70,8 +70,8 @@ function moveOrCopyFileWithCollisionHandling(src, dst, operation, cb) {
|
|||
}
|
||||
|
||||
//
|
||||
// Move |src| -> |dst| renaming to file(1).ext, file(2).ext, etc.
|
||||
// in the case of collisions.
|
||||
// Move |src| -> |dst| renaming to file(1).ext, file(2).ext, etc.
|
||||
// in the case of collisions.
|
||||
//
|
||||
function moveFileWithCollisionHandling(src, dst, cb) {
|
||||
return moveOrCopyFileWithCollisionHandling(src, dst, 'move', cb);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue