Skip to content

Commit 2278e46

Browse files
committed
allow restoring of atimes
1 parent cdeeeff commit 2278e46

9 files changed

+34
-3
lines changed

ChangeLog

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
09 Aug 2009: 1.1.0-dev0 Miek <[email protected]>
22
* Format change: add username, groupname and mtime
3-
Always output the files' contents
3+
_Always_ output the files' contents
44
%U username
55
%G groupname
66
%t is mtime of the fs object
77
* Adapt all utils to this format change
88
- rdup now handles -P itself
99
- rdup-tr does not do -P anymore
10+
- rdup is the only tool that accesses the files
11+
- rdup-tr only processes from stdin to stdout
12+
- rdup-up only processes stdin
1013
* Loads of code cleanups
1114
* Use OpenSSL in favor of libnettle
1215
* Change default install path /usr/local (Sebastian Kügler)

common.c

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ entry_dup(struct rdup *f)
2121
g->f_mode = f->f_mode;
2222
g->f_ctime = f->f_ctime;
2323
g->f_mtime = f->f_mtime;
24+
g->f_atime = f->f_atime;
2425
g->f_size = f->f_size;
2526
g->f_dev = f->f_dev;
2627
g->f_rdev = f->f_rdev;

crawler.c

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
extern gboolean opt_onefilesystem;
1010
extern gboolean opt_nobackup;
11+
extern gboolean opt_atime;
1112
extern time_t opt_timestamp;
1213
extern gint opt_verbose;
1314
extern GSList *pregex_list;
@@ -54,6 +55,7 @@ dir_prepend(GTree *t, char *path, GHashTable *u, GHashTable *g)
5455
e.f_group = lookup_group(g, e.f_gid);
5556
e.f_ctime = s.st_ctime;
5657
e.f_mtime = s.st_mtime;
58+
e.f_atime = s.st_atime;
5759
e.f_mode = s.st_mode;
5860
e.f_size = s.st_size;
5961
e.f_dev = s.st_dev;
@@ -120,6 +122,16 @@ dir_crawl(GTree *t, GHashTable *linkhash, GHashTable *userhash,
120122
current_dev = s.st_dev;
121123

122124
while((dent = readdir(dir))) {
125+
if (opt_atime) {
126+
struct utimbuf ut;
127+
ut.actime = s.st_atime;
128+
ut.modtime = s.st_mtime;
129+
/* BUGBUG */
130+
fprintf(stderr, "Resetting access\n");
131+
if (utime(path, &ut) == -1)
132+
msg(_("Failed to reset atime: '%s\': %s"), path, strerror(errno));
133+
}
134+
123135
if (!strcmp(dent->d_name, ".") ||
124136
!strcmp(dent->d_name, ".."))
125137
continue;
@@ -157,6 +169,7 @@ dir_crawl(GTree *t, GHashTable *linkhash, GHashTable *userhash,
157169
pop.f_group = lookup_group(grouphash, pop.f_gid);
158170
pop.f_ctime = s.st_ctime;
159171
pop.f_mtime = s.st_mtime;
172+
pop.f_atime = s.st_atime;
160173
pop.f_mode = s.st_mode;
161174
pop.f_size = s.st_size;
162175
pop.f_dev = s.st_dev;
@@ -234,6 +247,7 @@ dir_crawl(GTree *t, GHashTable *linkhash, GHashTable *userhash,
234247
dirstack[d]->f_group = lookup_group(grouphash, s.st_gid);
235248
dirstack[d]->f_ctime = s.st_ctime;
236249
dirstack[d]->f_mtime = s.st_mtime;
250+
dirstack[d]->f_atime = s.st_atime;
237251
dirstack[d]->f_mode = s.st_mode;
238252
dirstack[d]->f_size = s.st_size;
239253
dirstack[d]->f_dev = s.st_dev;

doc/rdup.1.in

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ trailing slash.
166166
.RE
167167

168168
.TP
169+
.B \-a
170+
Restore the original access times on the files and directories.
169171
.B \-c
170172
Force output to the tty. Normally \fBrdup-tr\fR wants to see it's
171173
output redirected.

entry.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ parse_entry(char *buf, size_t l)
5959
e->f_lnk = 0;
6060
e->f_ctime = s->st_ctime;
6161
e->f_mtime = s->st_mtime;
62+
e->f_atime = s->st_atime;
6263

6364
/* you will loose hardlink information here
6465
* as 'stat' cannot check this */
@@ -306,7 +307,7 @@ stat_from_rdup(struct rdup *e)
306307
s->st_rdev = e->f_rdev;
307308
s->st_ctime = e->f_ctime;
308309
s->st_mtime = e->f_mtime;
309-
s->st_atime = 0;
310+
s->st_atime = e->f_atime;
310311

311312
/*
312313
struct stat {

entry.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct rdup {
1818
mode_t f_mode; /* mode bits */
1919
time_t f_ctime; /* change time of the inode */
2020
time_t f_mtime; /* modification time of the inode */
21+
time_t f_atime; /* modification time of the inode */
2122
off_t f_size; /* file size */
2223
dev_t f_dev; /* ID of device containing file */
2324
dev_t f_rdev; /* device ID (if special file), we use this for major, minor */

fs-up.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static gboolean
2525
mk_time(struct rdup *e)
2626
{
2727
struct utimbuf ut;
28-
/* don't carry the a_time, how cares anyway with noatime? */
28+
/* we don't carry the a_time, how cares anyway with noatime? */
2929
ut.actime = ut.modtime = e->f_mtime;
3030

3131
if (utime(e->f_name, &ut) == -1)

gfunc.c

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
extern gboolean opt_removed;
1313
extern gboolean opt_modified;
1414
extern gboolean opt_skip;
15+
extern gboolean opt_atime;
1516
extern gint opt_verbose;
1617
extern char *opt_format;
1718
extern time_t opt_timestamp;
@@ -150,10 +151,17 @@ cat(FILE *fp, char *filename)
150151
static void
151152
entry_cat_data(FILE *fp, struct rdup *e)
152153
{
154+
struct utimbuf ut;
155+
ut.actime = e->f_atime;
156+
ut.modtime = e->f_mtime;
157+
153158
if (S_ISREG(e->f_mode) && e->f_lnk == 0) {
154159
if (!cat(fp, e->f_name))
155160
exit(EXIT_FAILURE);
156161

162+
if (opt_atime)
163+
if (utime(e->f_name, &ut) == -1)
164+
msg(_("Failed to reset atime: '%s\': %s"), e->f_name, strerror(errno));
157165
return;
158166
}
159167
}

rdup.c

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ g_tree_read_file(FILE *fp)
203203
e->f_gid = 0; /* keep this 0 for now */
204204
e->f_ctime = 0;
205205
e->f_mtime = 0;
206+
e->f_atime = 0;
206207
e->f_user = NULL;
207208
e->f_group = NULL;
208209
e->f_dev = f_dev;

0 commit comments

Comments
 (0)