Skip to content

Commit

Permalink
improve move file
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Sep 20, 2023
1 parent cd96bc1 commit f0c698c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/demo/platform/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ tb_int_t tb_demo_platform_file_main(tb_int_t argc, tb_char_t** argv)
// exit file
if (ifile) tb_file_exit(ifile);
if (ofile) tb_file_exit(ofile);
#elif 0
#elif 1
tb_bool_t ok = tb_file_rename(argv[1], argv[2]);
tb_trace_i("rename: %s => %s %s", argv[1], argv[2], ok? "ok" : "failed");
#elif 1
Expand Down
7 changes: 3 additions & 4 deletions src/tbox/platform/windows/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,15 @@ tb_bool_t tb_file_rename(tb_char_t const* path, tb_char_t const* dest)
if (!tb_path_absolute_w(dest, full1, TB_PATH_MAXN)) return tb_false;

// rename it
if (!MoveFileExW(full0, full1, MOVEFILE_REPLACE_EXISTING))
DWORD flags = MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH;
if (!MoveFileExW(full0, full1, flags))
{
// make directory
tb_file_mkdir(full1);

// rename it again
return MoveFileExW(full0, full1, MOVEFILE_REPLACE_EXISTING);
return MoveFileExW(full0, full1, flags);
}

// ok
return tb_true;
}
tb_bool_t tb_file_link(tb_char_t const* path, tb_char_t const* dest)
Expand Down

0 comments on commit f0c698c

Please sign in to comment.