Parcourir la source

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

Sam Atkins il y a 11 mois
Parent
commit
46eb4ed2b9

+ 4 - 0
packages/backend/src/api/APIError.js

@@ -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': {

+ 1 - 1
packages/backend/src/filesystem/hl_operations/hl_readdir.js

@@ -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;

+ 1 - 0
packages/puter-js-common/src/PosixError.js

@@ -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);