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 28, 2024
1 parent bfaa477 commit 416f4d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
19 changes: 19 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,24 @@ 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 {
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 });
const is_dir = 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
20 changes: 19 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 @@ -426,9 +426,11 @@ mocha.describe('namespace_fs', function() {

const dir_1 = '/a/b/c/';
const dir_2 = '/a/b/';
const dir_3 = '/x/y/z/';
const upload_key_1 = dir_1 + 'upload_key_1';
const upload_key_2 = dir_1 + 'upload_key_2';
const upload_key_3 = dir_2 + 'upload_key_3';
const upload_key_4 = dir_3 + 'upload_key_4';
const data = crypto.randomBytes(100);

mocha.before(async function() {
Expand Down Expand Up @@ -472,6 +474,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, upload_key_4, dummy_object_sdk, source);
await delete_object(ns_tmp, upload_bkt, '/x/y/z', 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 416f4d5

Please sign in to comment.