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 517a8a5 commit 548aa6b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/tbox/platform/windows/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ static tb_long_t tb_directory_walk_copy(tb_char_t const* path, tb_file_info_t co
tb_size_t size = tuple[1].ul;
tb_char_t const* name = path + size;

// the copy flags
tb_size_t flags = tuple[2].ul;

// the dest file path
tb_char_t dpath[8192] = {0};
tb_snprintf(dpath, 8192, "%s\\%s", dest, name[0] == '\\'? name + 1 : name);
Expand All @@ -77,10 +80,12 @@ static tb_long_t tb_directory_walk_copy(tb_char_t const* path, tb_file_info_t co
}

// copy
tb_bool_t ok = tb_true;
tb_bool_t skip_recursion = tb_false;
switch (info->type)
{
case TB_FILE_TYPE_FILE:
if (!tb_file_copy(path, dpath, TB_FILE_COPY_NONE)) tuple[2].b = tb_false;
ok = tb_file_copy(path, dpath, flags);
break;
case TB_FILE_TYPE_DIRECTORY:
{
Expand All @@ -97,7 +102,11 @@ static tb_long_t tb_directory_walk_copy(tb_char_t const* path, tb_file_info_t co
default:
break;
}
return TB_DIRECTORY_WALK_CODE_CONTINUE;
tuple[3].b = ok;
tb_size_t retcode = TB_DIRECTORY_WALK_CODE_CONTINUE;
if (skip_recursion)
retcode |= TB_DIRECTORY_WALK_CODE_SKIP_RECURSION;
return retcode;
}
static tb_long_t tb_directory_walk_impl(tb_wchar_t const* path, tb_long_t recursion, tb_bool_t prefix, tb_directory_walk_func_t func, tb_cpointer_t priv)
{
Expand Down Expand Up @@ -330,7 +339,8 @@ tb_bool_t tb_directory_copy(tb_char_t const* path, tb_char_t const* dest, tb_siz
tb_value_t tuple[3];
tuple[0].cstr = dest;
tuple[1].ul = tb_strlen(path);
tuple[2].b = tb_true;
tuple[2].ul = flags;
tuple[3].b = tb_true;
tb_directory_walk(path, -1, tb_true, tb_directory_walk_copy, tuple);

// ok?
Expand Down

0 comments on commit 548aa6b

Please sign in to comment.