fix: rename across directories working

This commit is contained in:
Arun Bose 2021-10-16 18:06:13 +05:30 committed by David Humphrey
parent 5f872f0f24
commit 24697a3ed9
8 changed files with 29344 additions and 66 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ node_modules
.env .env
*~ *~
.vscode .vscode
.idea
# Parcel build dirs # Parcel build dirs
.cache .cache

10712
dist/filer.js vendored

File diff suppressed because it is too large Load Diff

2
dist/filer.js.map vendored

File diff suppressed because one or more lines are too long

182
dist/filer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

18460
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -480,7 +480,7 @@ function access_file(context, path, mode, callback) {
} }
// In any other case, the file isn't accessible // In any other case, the file isn't accessible
callback(new Errors.EACCES('permission denied',path)) ; callback(new Errors.EACCES('permission denied',path)) ;
}); });
} }
@ -1079,7 +1079,7 @@ function unlink_node(context, path, callback) {
context.putObject(fileNode.id, fileNode, function(error) { context.putObject(fileNode.id, fileNode, function(error) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
update_node_times(context, path, fileNode, { ctime: Date.now() }, update_directory_data); update_node_times(context, path, fileNode, { ctime: Date.now() }, update_directory_data);
} }
}); });
@ -1177,7 +1177,7 @@ function read_directory(context, path, options, callback) {
callback(error, dirEnts); callback(error, dirEnts);
}); });
} }
else { else {
callback(null, files); callback(null, files);
} }
@ -1275,12 +1275,12 @@ function make_symbolic_link(context, srcpath, dstpath, callback) {
// but store both versions, since we'll use the relative one in readlink(). // but store both versions, since we'll use the relative one in readlink().
if(!isAbsolutePath(srcpath)) { if(!isAbsolutePath(srcpath)) {
fileNode.symlink_relpath = srcpath; fileNode.symlink_relpath = srcpath;
srcpath = Path.resolve(parentPath, srcpath); srcpath = Path.resolve(parentPath, srcpath);
} }
fileNode.size = srcpath.length; fileNode.size = srcpath.length;
fileNode.data = srcpath; fileNode.data = srcpath;
context.putObject(fileNode.id, fileNode, update_directory_data); context.putObject(fileNode.id, fileNode, update_directory_data);
}); });
} }
@ -1758,7 +1758,7 @@ function mkdir(context, path, mode, callback) {
mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback); mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback);
if(!mode) return; if(!mode) return;
} }
make_directory(context, path, callback); make_directory(context, path, callback);
} }
@ -1776,14 +1776,14 @@ function mkdtemp(context, prefix, options, callback) {
callback = arguments[arguments.length - 1]; callback = arguments[arguments.length - 1];
if(!prefix) { if(!prefix) {
return callback(new Error('filename prefix is required')); return callback(new Error('filename prefix is required'));
} }
let random = shared.randomChars(6); let random = shared.randomChars(6);
var path = prefix + '-' + random; var path = prefix + '-' + random;
make_directory(context, path, function(error) { make_directory(context, path, function(error) {
callback(error, path); callback(error, path);
}); });
} }
function rmdir(context, path, callback) { function rmdir(context, path, callback) {
@ -2326,7 +2326,7 @@ function rename(context, oldpath, newpath, callback) {
newpath = normalize(newpath); newpath = normalize(newpath);
var oldParentPath = Path.dirname(oldpath); var oldParentPath = Path.dirname(oldpath);
var newParentPath = Path.dirname(oldpath); var newParentPath = Path.dirname(newpath);
var oldName = Path.basename(oldpath); var oldName = Path.basename(oldpath);
var newName = Path.basename(newpath); var newName = Path.basename(newpath);
var oldParentDirectory, oldParentData; var oldParentDirectory, oldParentData;

View File

@ -20,7 +20,7 @@ describe('fs.rename', function() {
if(error) throw error; if(error) throw error;
fs.rename('/myfile', '/myfile', function(error) { fs.rename('/myfile', '/myfile', function(error) {
expect(error).not.to.exist; expect(error).not.to.exist;
done(); done();
}); });
}); });
@ -108,6 +108,35 @@ describe('fs.rename', function() {
}); });
}); });
it('should rename an existing directory into another sub directory', () => {
var fsPromises = util.fs().promises;
return fsPromises.mkdir('/mydir')
.then(() => fsPromises.mkdir('/mydir/subdir'))
.then(() => fsPromises.mkdir('/anotherdir'))
.then(() => fsPromises.rename('/mydir', '/anotherdir/originaldir'))
.then(() => { fsPromises.stat('/mydir')
.catch((error) => {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
});
})
.then(() => { fsPromises.stat('/anotherdir/mydir')
.catch((error) => {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
});
})
.then(() => { fsPromises.stat('/anotherdir/originaldir/subdir')
.then(result => {
expect(result.nlinks).to.equal(1);
});
})
.catch((error) => {
if (error) throw error;
});
});
it('should rename an existing directory if the new path points to an existing directory', function(done) { it('should rename an existing directory if the new path points to an existing directory', function(done) {
var fs = util.fs(); var fs = util.fs();