Skip to content

Commit

Permalink
NSFS | Versioning | Delete of partial directory of nested key results…
Browse files Browse the repository at this point in the history
… in AccessDeniedError

Signed-off-by: naveenpaul1 <[email protected]>
  • Loading branch information
naveenpaul1 committed Oct 25, 2024
1 parent 8f1d6f8 commit 53771ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/sdk/namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,7 @@ class NamespaceFS {
* @returns {Promise<string>}
*/
async _find_version_path(fs_context, { key, version_id }, return_md_path) {
key = await this._get_correct_key_path(fs_context, key);
const cur_ver_path = return_md_path ? this._get_file_md_path({ key }) : this._get_file_path({ key });
if (!version_id) return cur_ver_path;

Expand All @@ -2778,6 +2779,27 @@ class NamespaceFS {
const versioned_path = this._get_version_path(key, version_id);
return versioned_path;
}
/**
* method append slash at the end of dir key when key misses last slash.
* @param {import('./nb').NativeFSContext} fs_context
* @param {string} key
*/
async _get_correct_key_path(fs_context, key) {
try {
let is_dir = false;
const key_path = path.normalize(path.join(this.bucket_path, key));
const key_state = await nb_native().fs.stat(fs_context, key_path, { skip_user_xattr: true });
if (key_state) {
is_dir = await native_fs_utils.isDirectory(key_state);
}
if (is_dir) {
key = key.endsWith('/') ? key : path.join(key, '/');
}
} catch (err) {
dbg.warn('NamespaceFS._correct_key_path : error while getting state for key ', key, err);
}
return key;
}

_throw_if_delete_marker(stat, params) {
if (this.versioning === versioning_status_enum.VER_ENABLED || this.versioning === versioning_status_enum.VER_SUSPENDED) {
Expand Down
18 changes: 17 additions & 1 deletion src/test/unit_tests/test_namespace_fs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (C) 2020 NooBaa */
/*eslint max-lines-per-function: ["error", 900]*/
/*eslint max-lines: ["error", 2100]*/
/*eslint max-lines: ["error", 2200]*/
'use strict';

const _ = require('lodash');
Expand Down Expand Up @@ -472,6 +472,22 @@ mocha.describe('namespace_fs', function() {

});

mocha.it('delete dir object without last slash - a/b/c', async function() {
const source = buffer_utils.buffer_to_read_stream(data);
await upload_object(ns_tmp, upload_bkt, dir_1, dummy_object_sdk, source);
await delete_object(ns_tmp, upload_bkt, '/a/b/c', dummy_object_sdk);

let entries;
try {
entries = await nb_native().fs.readdir(DEFAULT_FS_CONFIG, ns_tmp_bucket_path + dir_2);
} catch (e) {
assert.ifError(e);
}
console.log('stop when not empty - entries', entries);
assert.strictEqual(entries.length, 1);

});

mocha.after(async function() {
let entries_before;
let entries_after;
Expand Down

0 comments on commit 53771ce

Please sign in to comment.