Set O_NOATIME if we are the owner of the file or a superuser.

This commit is contained in:
Andreas Schneider 2008-06-16 17:48:48 +02:00
parent 8a9a4b18fb
commit 4246190524
3 changed files with 16 additions and 9 deletions

View file

@ -102,8 +102,8 @@ static int _csync_push_file(CSYNC *ctx, csync_file_stat_t *st) {
/* Open the source file */
ctx->replica = srep;
flags = O_RDONLY|O_NOFOLLOW;
/* O_NOATIME can only be set by the owner of the file or root */
if (st->uid == getuid()) {
/* O_NOATIME can only be set by the owner of the file or the superuser */
if (st->uid == getuid() || geteuid() == 0) {
flags |= O_NOATIME;
}
sfp = csync_vio_open(ctx, suri, O_RDONLY|O_NOFOLLOW, 0);

View file

@ -237,13 +237,19 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, unsigned int dept
fs = csync_vio_file_stat_new();
if (csync_vio_stat(ctx, filename, fs) == 0) {
if (fs->type == CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK) {
flag = CSYNC_FTW_FLAG_SLINK;
} else if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY) {
flag = CSYNC_FTW_FLAG_DIR;
} else {
flag = CSYNC_FTW_FLAG_FILE;
}
switch (fs->type) {
case CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK:
flag = CSYNC_FTW_FLAG_SLINK;
break;
case CSYNC_VIO_FILE_TYPE_DIRECTORY:
flag = CSYNC_FTW_FLAG_DIR;
break;
case CSYNC_VIO_FILE_TYPE_REGULAR:
flag = CSYNC_FTW_FLAG_FILE;
default:
flag = CSYNC_FTW_FLAG_SPEC;
break;
};
} else {
flag = CSYNC_FTW_FLAG_NSTAT;
}

View file

@ -35,6 +35,7 @@ enum csync_ftw_flags_e {
CSYNC_FTW_FLAG_DNR, /* Unreadable directory. */
CSYNC_FTW_FLAG_NSTAT, /* Unstatable file. */
CSYNC_FTW_FLAG_SLINK, /* Symbolic link. */
CSYNC_FTW_FLAG_SPEC, /* Special file (fifo, ...). */
/* These flags are only passed from the `nftw' function. */
CSYNC_FTW_FLAG_DP, /* Directory, all subdirs have been visited. */
CSYNC_FTW_FLAG_SLN /* Symbolic link naming non-existing file. */