Skip to content

Commit 1d77755

Browse files
committed
rename versioning_status_enum to VERSIONING_STATUS_ENUM
and copy_status_enum to COPY_STATUS_ENUM and add `Object.freeze` Signed-off-by: shirady <57721533+shirady@users.noreply.github.com>
1 parent 259adab commit 1d77755

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/sdk/namespace_fs.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ const NULL_VERSION_ID = 'null';
6868
const NULL_VERSION_SUFFIX = '_' + NULL_VERSION_ID;
6969
const XATTR_STORAGE_CLASS_KEY = XATTR_USER_PREFIX + 'storage_class';
7070

71-
const versioning_status_enum = {
71+
const VERSIONING_STATUS_ENUM = Object.freeze({
7272
VER_ENABLED: 'ENABLED',
7373
VER_SUSPENDED: 'SUSPENDED',
7474
VER_DISABLED: 'DISABLED'
75-
};
75+
});
7676
const version_format = /^[a-z0-9]+$/;
7777

7878
// describes the status of the copy that was done, default is fallback
7979
// LINKED = the file was linked on the server side
8080
// IS_SAME_INODE = source and target are the same inode, nothing to copy
8181
// FALLBACK = will be reported when link on server side copy failed
8282
// or on non server side copy
83-
const copy_status_enum = {
83+
const COPY_STATUS_ENUM = Object.freeze({
8484
LINKED: 'LINKED',
8585
SAME_INODE: 'SAME_INODE',
8686
FALLBACK: 'FALLBACK'
87-
};
87+
});
8888

8989
const XATTR_METADATA_IGNORE_LIST = [
9090
XATTR_STORAGE_CLASS_KEY,
@@ -486,7 +486,7 @@ class NamespaceFS {
486486
this.bucket_id = bucket_id;
487487
this.namespace_resource_id = namespace_resource_id;
488488
this.access_mode = access_mode;
489-
this.versioning = (config.NSFS_VERSIONING_ENABLED && versioning) || versioning_status_enum.VER_DISABLED;
489+
this.versioning = (config.NSFS_VERSIONING_ENABLED && versioning) || VERSIONING_STATUS_ENUM.VER_DISABLED;
490490
this.stats = stats;
491491
this.force_md5_etag = force_md5_etag;
492492
this.warmup_buffer = nb_native().fs.dio_buffer_alloc(4096);
@@ -1209,7 +1209,7 @@ class NamespaceFS {
12091209
await this._throw_if_storage_class_not_supported(params.storage_class);
12101210

12111211
upload_params = await this._start_upload(fs_context, object_sdk, file_path, params, open_mode);
1212-
if (!params.copy_source || upload_params.copy_res === copy_status_enum.FALLBACK) {
1212+
if (!params.copy_source || upload_params.copy_res === COPY_STATUS_ENUM.FALLBACK) {
12131213
// We are taking the buffer size closest to the sized upload
12141214
const bp = multi_buffer_pool.get_buffers_pool(params.size);
12151215
const upload_res = await bp.sem.surround_count(
@@ -1254,16 +1254,16 @@ class NamespaceFS {
12541254

12551255
let copy_res;
12561256
if (force_copy_fallback) {
1257-
copy_res = copy_status_enum.FALLBACK;
1257+
copy_res = COPY_STATUS_ENUM.FALLBACK;
12581258
} else if (params.copy_source) {
12591259
copy_res = await this._try_copy_file(fs_context, params, file_path, upload_path);
12601260
}
12611261

12621262
if (copy_res) {
1263-
if (copy_res !== copy_status_enum.FALLBACK) {
1263+
if (copy_res !== COPY_STATUS_ENUM.FALLBACK) {
12641264
// open file after copy link/same inode should use read open mode
12651265
open_mode = config.NSFS_OPEN_READ_MODE;
1266-
if (copy_res === copy_status_enum.SAME_INODE) open_path = file_path;
1266+
if (copy_res === COPY_STATUS_ENUM.SAME_INODE) open_path = file_path;
12671267
}
12681268
}
12691269
const target_file = await native_fs_utils.open_file(fs_context, this.bucket_path, open_path, open_mode);
@@ -1280,15 +1280,15 @@ class NamespaceFS {
12801280
const source_file_path = await this._find_version_path(fs_context, params.copy_source);
12811281
await this._check_path_in_bucket_boundaries(fs_context, source_file_path);
12821282
// await this._fail_if_archived_or_sparse_file(fs_context, source_file_path, stat);
1283-
let res = copy_status_enum.FALLBACK;
1283+
let res = COPY_STATUS_ENUM.FALLBACK;
12841284
if (this._is_versioning_disabled()) {
12851285
try {
12861286
// indicates a retry situation in which the source and target point to the same inode
12871287
const same_inode = await this._is_same_inode(fs_context, source_file_path, file_path);
1288-
if (same_inode) return copy_status_enum.SAME_INODE;
1288+
if (same_inode) return COPY_STATUS_ENUM.SAME_INODE;
12891289
// Doing a hard link.
12901290
await nb_native().fs.link(fs_context, source_file_path, upload_path);
1291-
res = copy_status_enum.LINKED;
1291+
res = COPY_STATUS_ENUM.LINKED;
12921292
} catch (e) {
12931293
dbg.warn('NamespaceFS: COPY using link failed with:', e);
12941294
}
@@ -1337,8 +1337,8 @@ class NamespaceFS {
13371337
async _finish_upload({ fs_context, params, open_mode, target_file, upload_path, file_path, digest = undefined,
13381338
copy_res = undefined, offset }) {
13391339
const part_upload = file_path === upload_path;
1340-
const same_inode = params.copy_source && copy_res === copy_status_enum.SAME_INODE;
1341-
const should_replace_xattr = params.copy_source ? copy_res === copy_status_enum.FALLBACK : true;
1340+
const same_inode = params.copy_source && copy_res === COPY_STATUS_ENUM.SAME_INODE;
1341+
const should_replace_xattr = params.copy_source ? copy_res === COPY_STATUS_ENUM.FALLBACK : true;
13421342
const is_dir_content = this._is_directory_content(file_path, params.key);
13431343

13441344
const stat = await target_file.stat(fs_context);
@@ -2693,15 +2693,15 @@ class NamespaceFS {
26932693
//////////////////////////
26942694

26952695
_is_versioning_enabled() {
2696-
return this.versioning === versioning_status_enum.VER_ENABLED;
2696+
return this.versioning === VERSIONING_STATUS_ENUM.VER_ENABLED;
26972697
}
26982698

26992699
_is_versioning_disabled() {
2700-
return this.versioning === versioning_status_enum.VER_DISABLED;
2700+
return this.versioning === VERSIONING_STATUS_ENUM.VER_DISABLED;
27012701
}
27022702

27032703
_is_versioning_suspended() {
2704-
return this.versioning === versioning_status_enum.VER_SUSPENDED;
2704+
return this.versioning === VERSIONING_STATUS_ENUM.VER_SUSPENDED;
27052705
}
27062706

27072707
_get_version_id_by_mode(stat) {
@@ -2786,7 +2786,7 @@ class NamespaceFS {
27862786
}
27872787

27882788
_throw_if_delete_marker(stat, params) {
2789-
if (this.versioning === versioning_status_enum.VER_ENABLED || this.versioning === versioning_status_enum.VER_SUSPENDED) {
2789+
if (this.versioning === VERSIONING_STATUS_ENUM.VER_ENABLED || this.versioning === VERSIONING_STATUS_ENUM.VER_SUSPENDED) {
27902790
const xattr_delete_marker = stat.xattr[XATTR_DELETE_MARKER];
27912791
if (xattr_delete_marker) {
27922792
const basic_err = error_utils.new_error_code('ENOENT', 'Entry is a delete marker');

0 commit comments

Comments
 (0)