Skip to content

Commit

Permalink
NC | Config Files | Create Config Files Size 0 Bug Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <[email protected]>
  • Loading branch information
romayalon committed Feb 25, 2025
1 parent a85e1c2 commit 674a402
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/util/native_fs_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,8 @@ function get_config_files_tmpdir() {
* @param {string} config_data
*/
async function create_config_file(fs_context, schema_dir, config_path, config_data) {
const is_gpfs = _is_gpfs(fs_context);
const open_mode = is_gpfs ? 'wt' : 'w';
const open_mode = 'w';
let upload_tmp_file;
let gpfs_dst_file;
try {
// validate config file doesn't exist
try {
Expand All @@ -336,37 +334,25 @@ async function create_config_file(fs_context, schema_dir, config_path, config_da
dbg.log1('create_config_file:: config_path:', config_path, 'config_data:', config_data, 'is_gpfs:', open_mode);
// create config dir if it does not exist
await _create_path(schema_dir, fs_context, config.BASE_MODE_CONFIG_DIR);
// when using GPFS open dst file as soon as possible for later linkat validation
if (is_gpfs) gpfs_dst_file = await open_file(fs_context, schema_dir, config_path, 'w*', config.BASE_MODE_CONFIG_FILE);

// open tmp file (in GPFS we open the parent dir using wt open mode)
const tmp_dir_path = path.join(schema_dir, get_config_files_tmpdir());
let open_path = is_gpfs ? config_path : await _generate_unique_path(fs_context, tmp_dir_path);
const open_path = await _generate_unique_path(fs_context, tmp_dir_path);
upload_tmp_file = await open_file(fs_context, schema_dir, open_path, open_mode, config.BASE_MODE_CONFIG_FILE);

// write tmp file data
await upload_tmp_file.writev(fs_context, [Buffer.from(config_data)], 0);

// moving tmp file to config path atomically
let src_stat;
let gpfs_options;
if (is_gpfs) {
gpfs_options = { dst_file: gpfs_dst_file, dir_file: upload_tmp_file };
// open path in GPFS is the parent dir
open_path = schema_dir;
} else {
src_stat = await nb_native().fs.stat(fs_context, open_path);
}
dbg.log1('create_config_file:: moving from:', open_path, 'to:', config_path, 'is_gpfs=', is_gpfs);
dbg.log1('create_config_file:: moving from:', open_path, 'to:', config_path);

await safe_move(fs_context, open_path, config_path, src_stat, gpfs_options, tmp_dir_path);
await nb_native().fs.link(fs_context, open_path, config_path);

dbg.log1('create_config_file:: done', config_path);
} catch (err) {
dbg.error('create_config_file:: error', err);
throw err;
} finally {
await finally_close_files(fs_context, [upload_tmp_file, gpfs_dst_file]);
await finally_close_files(fs_context, [upload_tmp_file]);
}
}

Expand Down

0 comments on commit 674a402

Please sign in to comment.