Skip to content

Commit 46eb4ed

Browse files
AtkinsSJKernelDeimos
authored andcommitted
fix: Throw an error when readdir is called on a non-directory
1 parent a136ee5 commit 46eb4ed

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

packages/backend/src/api/APIError.js

+4
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ module.exports = class APIError {
236236
status: 422,
237237
message: 'Directory is not empty.',
238238
},
239+
'readdir_of_non_directory': {
240+
status: 422,
241+
message: 'Readdir target must be a directory.',
242+
},
239243

240244
// Write
241245
'offset_without_existing_file': {

packages/backend/src/filesystem/hl_operations/hl_readdir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class HLReadDir extends HLFilesystemOperation {
3838
if ( ! await svc_acl.check(actor, subject, 'see') ) {
3939
throw await svc_acl.get_safe_acl_error(actor, subject, 'see');
4040
}
41-
return [await subject.getSafeEntry()];
41+
throw APIError.create('readdir_of_non_directory');
4242
}
4343

4444
let children;

packages/puter-js-common/src/PosixError.js

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class PosixError extends Error {
156156
case 'missing_expected_metadata': return new PosixError(ErrorCodes.EINVAL, e.message);
157157
case 'overwrite_and_dedupe_exclusive': return new PosixError(ErrorCodes.EINVAL, e.message);
158158
case 'not_empty': return new PosixError(ErrorCodes.ENOTEMPTY, e.message);
159+
case 'readdir_of_non_directory': return new PosixError(ErrorCodes.ENOTDIR, e.message);
159160

160161
// Write
161162
case 'offset_without_existing_file': return new PosixError(ErrorCodes.ENOENT, e.message);

0 commit comments

Comments
 (0)