Skip to content

Commit

Permalink
Optimize scan_dir tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin authored and zhengshuxin committed Jan 4, 2025
1 parent 94e0d4f commit 0050601
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions lib_acl_cpp/samples/scan_dir/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ static void ls_dir(acl::scan_dir& scan, const char* path, bool recursive,
bool fullpath)
{
if (scan.open(path, recursive) == false) {
logger_error("open path: %s error: %s",
path, acl::last_serror());
logger_error("open path: %s error: %s", path, acl::last_serror());
return;
}

Expand Down Expand Up @@ -85,7 +84,7 @@ static bool get_relative_path(const char* spath, const char* filepath,
return true;
}

static bool compare_files(const char* sfile, const char* dfile)
static bool compare_files(const char* sfile, const char* dfile, bool ignore)
{
acl::string sbuf, dbuf;

Expand All @@ -95,6 +94,8 @@ static bool compare_files(const char* sfile, const char* dfile)
}

if (acl::ifstream::load(dfile, &dbuf) == false) {
if (acl::last_error() == ENOENT && ignore)
return true;
logger_error("load dfile %s error %s", dfile, acl::last_serror());
return false;
}
Expand All @@ -103,7 +104,7 @@ static bool compare_files(const char* sfile, const char* dfile)
}

static void diff_path(acl::scan_dir& scan, const char* spath, const char* dpath,
bool recursive, const char* file_types, bool show_all)
bool recursive, const char* file_types, bool show_all, bool ignore)
{
if (scan.open(spath, recursive) == false) {
logger_error("open path: %s error: %s",
Expand Down Expand Up @@ -136,7 +137,7 @@ static void diff_path(acl::scan_dir& scan, const char* spath, const char* dpath,
acl::string dfilepath;
dfilepath << dpath << path;
n++;
bool equal = compare_files(filepath, dfilepath);
bool equal = compare_files(filepath, dfilepath, ignore);
if (!equal) {
printf("diff %s\t%s\r\n", filepath, dfilepath.c_str());
} else if (show_all) {
Expand All @@ -154,18 +155,19 @@ static void usage(const char* procname)
" -d destination path\r\n"
" -e file_types\r\n"
" -A [show all status including same files]\r\n"
" -I [if ignore the files not included in destination path]\r\n"
" -r [if recursive, default: false]\r\n"
" -a [if get fullpath, default: false]\r\n", procname);
}

int main(int argc, char* argv[])
{
int ch;
bool recursive = false, fullpath = false, show_all = false;
bool recursive = false, fullpath = false, show_all = false, ignore = false;
acl::string dpath, spath, mode, types("c;cpp;cc;cxx;h;hpp;hxx");
acl::log::stdout_open(true);

while ((ch = getopt(argc, argv, "hs:d:t:rae:A")) > 0) {
while ((ch = getopt(argc, argv, "hs:d:t:rae:AI")) > 0) {
switch (ch) {
case 'h':
usage(argv[0]);
Expand All @@ -191,6 +193,9 @@ int main(int argc, char* argv[])
case 'A':
show_all = true;
break;
case 'I':
ignore = true;
break;
default:
break;
}
Expand All @@ -217,7 +222,7 @@ int main(int argc, char* argv[])
}
if (!dpath.end_with("/"))
dpath += "/";
diff_path(scan, spath, dpath, recursive, types, show_all);
diff_path(scan, spath, dpath, recursive, types, show_all, ignore);
} else
ls_all(scan, spath, recursive, fullpath);

Expand Down
4 changes: 2 additions & 2 deletions lib_fiber/cpp/src/fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ int fiber::get_errno() const

bool fiber::is_ready() const
{
return f_ != NULL && acl_fiber_status(f_) == FIBER_STATUS_READY;
return f_ && acl_fiber_status(f_) == FIBER_STATUS_READY;
}

bool fiber::is_suspended() const
{
return f_ != NULL && acl_fiber_status(f_) == FIBER_STATUS_SUSPEND;
return f_ && acl_fiber_status(f_) == FIBER_STATUS_SUSPEND;
}

void fiber::set_errno(int errnum)
Expand Down

0 comments on commit 0050601

Please sign in to comment.