Skip to content

Commit

Permalink
improve copy directory
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Feb 6, 2024
1 parent f132aac commit 60ffa77
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/tbox/platform/windows/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,33 @@ tb_bool_t tb_file_copy(tb_char_t const* path, tb_char_t const* dest, tb_size_t f
tb_file_info_t info = {0};
if (flags & TB_FILE_COPY_LINK && tb_file_info(path, &info) && info.flags & TB_FILE_FLAG_LINK)
{
tb_file_mkdir(full1);
tb_trace_i("tb_file_copy link: %s %s", path, dest);
if (tb_kernel32()->CopyFileExW)
if (tb_kernel32()->CopyFileExW && tb_kernel32()->CopyFileExW(full0, full1, tb_null, tb_null, FALSE, COPY_FILE_COPY_SYMLINK))
return tb_true;
tb_trace_i("copy file content");
// we should read file content to copy it
tb_bool_t ok = tb_false;
tb_file_ref_t ifile = tb_file_init(path, TB_FILE_MODE_RW);
tb_file_ref_t ofile = tb_file_init(dest, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC);
if (ifile && ofile)
{
tb_bool_t ok = (tb_bool_t)tb_kernel32()->CopyFileExW(full0, full1, tb_null, tb_null, FALSE, COPY_FILE_COPY_SYMLINK);
tb_trace_i("ok: %d, error: %d", GetLastError());
return ok;
tb_hize_t writ = 0;
tb_hize_t size = tb_file_size(ifile);
while (writ < size)
{
tb_long_t real = tb_file_writf(ofile, ifile, writ, size - writ);
if (real > 0) writ += real;
else break;
}
if (writ == size) ok = tb_true;
}
// TODO we should read file content to copy it
// ...

// exit file
if (ifile) tb_file_exit(ifile);
if (ofile) tb_file_exit(ofile);
tb_trace_i("copy: %d", ok);
return ok;
}

// copy it
Expand Down

0 comments on commit 60ffa77

Please sign in to comment.