Skip to content

Commit 7681865

Browse files
authored
Merge pull request #8811 from nadavMiz/content-dir-empty-get
NSFS | close stream when getting empty content dir
2 parents 6d53494 + 2f27896 commit 7681865

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/sdk/namespace_fs.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,12 @@ class NamespaceFS {
10221022
// NOTE: don't move this code after the open
10231023
// this can lead to ENOENT failures due to file not exists when content size is 0
10241024
// if entry is a directory object and its content size = 0 - return empty response
1025-
if (await this._is_empty_directory_content(file_path, fs_context, params)) return null;
1025+
if (await this._is_empty_directory_content(file_path, fs_context, params)) {
1026+
res.end();
1027+
// since we don't write anything to the stream wait_finished might not be needed. added just in case there is a delay
1028+
await stream_utils.wait_finished(res, { signal: object_sdk.abort_controller.signal });
1029+
return null;
1030+
}
10261031

10271032
file = await nb_native().fs.open(
10281033
fs_context,

src/test/unit_tests/test_namespace_fs.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ mocha.describe('namespace_fs', function() {
547547
const dir_2 = '/a/b/';
548548
const upload_key_1 = dir_1 + 'upload_key_1/';
549549
const upload_key_2 = dir_2 + 'upload_key_2/';
550+
const upload_key_empty = 'empty_key/';
550551
const data = crypto.randomBytes(100);
551552

552553
mocha.before(async function() {
@@ -558,6 +559,22 @@ mocha.describe('namespace_fs', function() {
558559
console.log('upload_object with trailing / response', inspect(upload_res));
559560
});
560561

562+
mocha.it('get empty content dir', async function() {
563+
await ns_tmp.upload_object({
564+
bucket: upload_bkt,
565+
key: upload_key_empty,
566+
source_stream: buffer_utils.buffer_to_read_stream(crypto.randomBytes(0)),
567+
size: 0
568+
}, dummy_object_sdk);
569+
570+
const read_res = buffer_utils.write_stream();
571+
await ns_tmp.read_object_stream({
572+
bucket: upload_bkt,
573+
key: upload_key_empty,
574+
}, dummy_object_sdk, read_res);
575+
assert(read_res.writableEnded);
576+
});
577+
561578
mocha.it(`delete the path - stop when not empty and key with trailing /`, async function() {
562579
const upload_res = await ns_tmp.upload_object({
563580
bucket: upload_bkt,
@@ -574,11 +591,17 @@ mocha.describe('namespace_fs', function() {
574591
});
575592

576593
mocha.after(async function() {
577-
const delete_res = await ns_tmp.delete_object({
594+
let delete_res = await ns_tmp.delete_object({
578595
bucket: upload_bkt,
579596
key: upload_key_2,
580597
}, dummy_object_sdk);
581598
console.log('delete_object with trailing / (key 2) response', inspect(delete_res));
599+
600+
delete_res = await ns_tmp.delete_object({
601+
bucket: upload_bkt,
602+
key: upload_key_empty,
603+
}, dummy_object_sdk);
604+
console.log('delete_object with trailing / (empty content dir) response', inspect(delete_res));
582605
});
583606
});
584607

0 commit comments

Comments
 (0)