fix: Throw an error when readdir is called on a non-directory

This commit is contained in:
Sam Atkins
2024-06-24 11:23:29 +01:00
committed by Eric Dubé
parent a136ee5edd
commit 46eb4ed2b9
3 changed files with 6 additions and 1 deletions
+4
View File
@@ -236,6 +236,10 @@ module.exports = class APIError {
status: 422,
message: 'Directory is not empty.',
},
'readdir_of_non_directory': {
status: 422,
message: 'Readdir target must be a directory.',
},
// Write
'offset_without_existing_file': {
@@ -38,7 +38,7 @@ class HLReadDir extends HLFilesystemOperation {
if ( ! await svc_acl.check(actor, subject, 'see') ) {
throw await svc_acl.get_safe_acl_error(actor, subject, 'see');
}
return [await subject.getSafeEntry()];
throw APIError.create('readdir_of_non_directory');
}
let children;
@@ -156,6 +156,7 @@ class PosixError extends Error {
case 'missing_expected_metadata': return new PosixError(ErrorCodes.EINVAL, e.message);
case 'overwrite_and_dedupe_exclusive': return new PosixError(ErrorCodes.EINVAL, e.message);
case 'not_empty': return new PosixError(ErrorCodes.ENOTEMPTY, e.message);
case 'readdir_of_non_directory': return new PosixError(ErrorCodes.ENOTDIR, e.message);
// Write
case 'offset_without_existing_file': return new PosixError(ErrorCodes.ENOENT, e.message);