Skip to content

Commit

Permalink
fix remove directory with dead symbol link failed
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed May 10, 2017
1 parent feb9f7d commit 96433b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

* Fix create file mode to 0644
* Fix file and directory path bug
* Fix remove directory with dead symbol link failed

## v1.6.1

Expand Down Expand Up @@ -150,6 +151,7 @@

* 修复创建文件权限不对问题
* 修复文件和目录路径问题
* 修复无法移除带有无效软链的目录问题

## v1.6.1

Expand Down
43 changes: 16 additions & 27 deletions src/tbox/platform/posix/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,8 @@ static tb_bool_t tb_directory_walk_remove(tb_char_t const* path, tb_file_info_t
// check
tb_assert_and_check_return_val(path && info, tb_false);

// remove
switch (info->type)
{
case TB_FILE_TYPE_FILE:
tb_file_remove(path);
break;
case TB_FILE_TYPE_DIRECTORY:
remove(path);
break;
default:
break;
}
// remove file, directory and dead symbol link (info->type is none, file not exists)
remove(path);

// continue
return tb_true;
Expand Down Expand Up @@ -137,22 +127,21 @@ static tb_bool_t tb_directory_walk_impl(tb_char_t const* path, tb_bool_t recursi
tb_long_t n = tb_snprintf(temp, 4095, "%s%s%s", path, path[last] == '/'? "" : "/", name);
if (n >= 0) temp[n] = '\0';

// the file info
// get the file info (file maybe not exists, dead symbol link)
tb_file_info_t info = {0};
if (tb_file_info(temp, &info))
{
// do callback
if (prefix) ok = func(temp, &info, priv);
tb_check_break(ok);

// walk to the next directory
if (info.type == TB_FILE_TYPE_DIRECTORY && recursion) ok = tb_directory_walk_impl(temp, recursion, prefix, func, priv);
tb_check_break(ok);

// do callback
if (!prefix) ok = func(temp, &info, priv);
tb_check_break(ok);
}
tb_file_info(temp, &info);

// do callback
if (prefix) ok = func(temp, &info, priv);
tb_check_break(ok);

// walk to the next directory
if (info.type == TB_FILE_TYPE_DIRECTORY && recursion) ok = tb_directory_walk_impl(temp, recursion, prefix, func, priv);
tb_check_break(ok);

// do callback
if (!prefix) ok = func(temp, &info, priv);
tb_check_break(ok);
}
}

Expand Down

0 comments on commit 96433b6

Please sign in to comment.