Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSFS | close stream when getting empty content dir #8811

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sdk/namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,12 @@ class NamespaceFS {
// NOTE: don't move this code after the open
// this can lead to ENOENT failures due to file not exists when content size is 0
// if entry is a directory object and its content size = 0 - return empty response
if (await this._is_empty_directory_content(file_path, fs_context, params)) return null;
if (await this._is_empty_directory_content(file_path, fs_context, params)) {
res.end();
// since we don't write anything to the stream wait_finished might not be needed. added just in case there is a delay
await stream_utils.wait_finished(res, { signal: object_sdk.abort_controller.signal });
return null;
}

file = await nb_native().fs.open(
fs_context,
Expand Down
25 changes: 24 additions & 1 deletion src/test/unit_tests/test_namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ mocha.describe('namespace_fs', function() {
const dir_2 = '/a/b/';
const upload_key_1 = dir_1 + 'upload_key_1/';
const upload_key_2 = dir_2 + 'upload_key_2/';
const upload_key_empty = 'empty_key/';
const data = crypto.randomBytes(100);

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

mocha.it('get empty content dir', async function() {
await ns_tmp.upload_object({
bucket: upload_bkt,
key: upload_key_empty,
source_stream: buffer_utils.buffer_to_read_stream(crypto.randomBytes(0)),
size: 0
}, dummy_object_sdk);

const read_res = buffer_utils.write_stream();
await ns_tmp.read_object_stream({
bucket: upload_bkt,
key: upload_key_empty,
}, dummy_object_sdk, read_res);
assert(read_res.writableEnded);
});

mocha.it(`delete the path - stop when not empty and key with trailing /`, async function() {
const upload_res = await ns_tmp.upload_object({
bucket: upload_bkt,
Expand All @@ -574,11 +591,17 @@ mocha.describe('namespace_fs', function() {
});

mocha.after(async function() {
const delete_res = await ns_tmp.delete_object({
let delete_res = await ns_tmp.delete_object({
bucket: upload_bkt,
key: upload_key_2,
}, dummy_object_sdk);
console.log('delete_object with trailing / (key 2) response', inspect(delete_res));

delete_res = await ns_tmp.delete_object({
bucket: upload_bkt,
key: upload_key_empty,
}, dummy_object_sdk);
console.log('delete_object with trailing / (empty content dir) response', inspect(delete_res));
});
});

Expand Down