Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to not update the file last access time with dwalk #590

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/rst/dwalk.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ OPTIONS

Print files to the screen.

.. option:: --no-atime

Must bu used with --lite option. Do not update last file access time.

.. option:: -L, --dereference

Dereference symbolic links and walk the target file or directory
Expand Down
5 changes: 5 additions & 0 deletions man/dwalk.1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Print files to the screen.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-atime
Must be used with the \-\-lite option. Do not update the file last access time.
.UNINDENT
.INDENT 0.0
.TP
.B \-L, \-\-dereference
Dereference symbolic links and walk the target file or directory
that each symbolic link refers to.
Expand Down
3 changes: 3 additions & 0 deletions src/common/mfu_flist.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ mfu_walk_opts_t* mfu_walk_opts_new(void)
/* Don't dereference symbolic links by default */
opts->dereference = 0;

/* Don't update the file last access time */
opts->no_atime = 0;

return opts;
}

Expand Down
27 changes: 21 additions & 6 deletions src/common/mfu_flist_walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static flist_t* CURRENT_LIST;
static int SET_DIR_PERMS;
static int REMOVE_FILES;
static int DEREFERENCE;
static int NO_ATIME;
static mfu_file_t** CURRENT_PFILE;

/****************************************
Expand Down Expand Up @@ -180,11 +181,15 @@ struct linux_dirent {

static void walk_getdents_process_dir(const char* dir, CIRCLE_handle* handle)
{
int flags = O_RDONLY | O_DIRECTORY;
char buf[BUF_SIZE];

if (NO_ATIME)
flags |= O_NOATIME;

/* TODO: may need to try these functions multiple times */
mfu_file_t* mfu_file = *CURRENT_PFILE;
mfu_file_open(dir, O_RDONLY | O_DIRECTORY, mfu_file);
mfu_file_open(dir, flags, mfu_file);
if (mfu_file->fd == -1) {
/* print error */
MFU_LOG(MFU_LOG_ERR, "Failed to open directory for reading: `%s' (errno=%d %s)", dir, errno, strerror(errno));
Expand Down Expand Up @@ -605,6 +610,12 @@ void mfu_flist_walk_paths(uint64_t num_paths, const char** paths,
DEREFERENCE = 1;
}

/* if no_atime is set to 1 then set global variable */
NO_ATIME = 0;
if (walk_opts->no_atime) {
NO_ATIME = 1;
}

/* convert handle to flist_t */
flist_t* flist = (flist_t*) bflist;

Expand Down Expand Up @@ -657,11 +668,15 @@ void mfu_flist_walk_paths(uint64_t num_paths, const char** paths,
CIRCLE_cb_process(&walk_stat_process);
}
else {
/* walk directories using file types in readdir */
CIRCLE_cb_create(&walk_readdir_create);
CIRCLE_cb_process(&walk_readdir_process);
// CIRCLE_cb_create(&walk_getdents_create);
// CIRCLE_cb_process(&walk_getdents_process);
if (walk_opts->no_atime) {
/* walk directories without updating the file last access time */
CIRCLE_cb_create(&walk_getdents_create);
CIRCLE_cb_process(&walk_getdents_process);
} else {
/* walk directories using file types in readdir */
CIRCLE_cb_create(&walk_readdir_create);
CIRCLE_cb_process(&walk_readdir_process);
}
}

/* prepare callbacks and initialize variables for reductions */
Expand Down
1 change: 1 addition & 0 deletions src/common/mfu_param_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct {
int remove; /* flag option to remove files during walk */
int use_stat; /* flag option on whether or not to stat files during walk */
int dereference; /* flag option to dereference symbolic links */
int no_atime; /* flag option to not update the file last acess time */
} mfu_walk_opts_t;

typedef enum {
Expand Down
7 changes: 6 additions & 1 deletion src/dwalk/dwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ static void print_usage(void)
printf(" -d, --distribution <field>:<separators> \n - print distribution by field\n");
printf(" -f, --file_histogram - print default size distribution of items\n");
printf(" -p, --print - print files to screen\n");
printf(" --no-atime - use with -l; do not update the file last access time\n");
printf(" -L, --dereference - follow symbolic links\n");
printf(" --progress <N> - print progress every N seconds\n");
printf(" -v, --verbose - verbose output\n");
Expand Down Expand Up @@ -390,6 +391,7 @@ int main(int argc, char** argv)
{"distribution", 1, 0, 'd'},
{"file_histogram", 0, 0, 'f'},
{"print", 0, 0, 'p'},
{"no-atime", 0, 0, 'n'},
{"dereference", 0, 0, 'L'},
{"progress", 1, 0, 'R'},
{"verbose", 0, 0, 'v'},
Expand All @@ -401,7 +403,7 @@ int main(int argc, char** argv)
int usage = 0;
while (1) {
int c = getopt_long(
argc, argv, "i:o:tls:d:fpLvqh",
argc, argv, "i:o:tls:d:fpLvqhn",
long_options, &option_index
);

Expand Down Expand Up @@ -432,6 +434,9 @@ int main(int argc, char** argv)
case 'p':
print = 1;
break;
case 'n':
walk_opts->no_atime = 1;
break;
case 'L':
walk_opts->dereference = 1;
break;
Expand Down