diff options
author | Jan Kara <jack@suse.cz> | 2015-01-05 15:44:18 +0100 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2015-01-05 17:12:56 +0100 |
commit | 094306bbfdbaacf2b9920b6dc44a6ee155fea1c5 (patch) | |
tree | 58cfc19395a7ba71388ded03bd7b814860802f94 | |
parent | 33160239630e668413bcb915490f604f2870309a (diff) | |
download | quota-tools-094306bbfdbaacf2b9920b6dc44a6ee155fea1c5.tar.gz |
edquota: Do not unnecessarily overwrite limits/times
When user doesn't edit the file with limits / grace times, there is no
need to overwrite the values in quota files. Maybe admin really wanted
to cancel the operation by not writing the file.
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | common.c | 13 | ||||
-rw-r--r-- | common.h | 5 | ||||
-rw-r--r-- | edquota.c | 30 | ||||
-rw-r--r-- | po/cs.po | 2 | ||||
-rw-r--r-- | po/de.po | 2 | ||||
-rw-r--r-- | po/fr.po | 6 | ||||
-rw-r--r-- | po/pl.po | 2 |
7 files changed, 54 insertions, 6 deletions
@@ -125,3 +125,16 @@ void version(void) printf(_("Compiled with:%s\n"), COMPILE_OPTS); printf(_("Bugs to %s\n"), PACKAGE_BUGREPORT); } + +int timespec_cmp(struct timespec *a, struct timespec *b) +{ + if (a->tv_sec < b->tv_sec) + return -1; + if (a->tv_sec > b->tv_sec) + return 1; + if (a->tv_nsec < b->tv_nsec) + return -1; + if (a->tv_nsec > b->tv_nsec) + return 1; + return 0; +} @@ -7,6 +7,8 @@ #ifndef GUARD_COMMON_H #define GUARD_COMMON_H +#include <time.h> + #ifndef __attribute__ # if !defined __GNUC__ || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ # define __attribute__(x) @@ -44,4 +46,7 @@ char *sstrdup(const char *s); /* Print version string */ void version(void); +/* Compare two times */ +int timespec_cmp(struct timespec *a, struct timespec *b); + #endif /* GUARD_COMMON_H */ @@ -237,6 +237,8 @@ int main(int argc, char **argv) int tmpfd, ret, id; struct quota_handle **handles; char *tmpfil, *tmpdir = NULL; + struct stat st; + struct timespec mtime; gettexton(); progname = basename(argv[0]); @@ -282,6 +284,12 @@ int main(int argc, char **argv) ret = -1; goto out; } + if (stat(tmpfil, &st) < 0) { + errstr(_("Cannot stat file with times.\n")); + ret = -1; + goto out; + } + mtime = st.st_mtim; if (editprivs(tmpfil) < 0) { errstr(_("Error while editing grace times.\n")); ret = -1; @@ -295,6 +303,14 @@ int main(int argc, char **argv) */ if ((tmpfd = open(tmpfil, O_RDWR)) < 0) die(1, _("Cannot reopen!")); + if (stat(tmpfil, &st) < 0) { + errstr(_("Cannot stat file with times.\n")); + ret = -1; + goto out; + } + /* File not modified? */ + if (timespec_cmp(&mtime, &st.st_mtim) <= 0) + goto out; if (readtimes(handles, tmpfd) < 0) { errstr(_("Failed to parse grace times file.\n")); ret = -1; @@ -320,6 +336,12 @@ int main(int argc, char **argv) goto next_user; } } + if (stat(tmpfil, &st) < 0) { + errstr(_("Cannot stat file with times.\n")); + ret = -1; + goto out; + } + mtime = st.st_mtim; if (editprivs(tmpfil) < 0) { errstr(_("Error while editing quotas.\n")); ret = -1; @@ -333,6 +355,14 @@ int main(int argc, char **argv) */ if ((tmpfd = open(tmpfil, O_RDWR)) < 0) die(1, _("Cannot reopen!")); + if (stat(tmpfil, &st) < 0) { + errstr(_("Cannot stat file with times.\n")); + ret = -1; + goto next_user; + } + /* File not modified? */ + if (timespec_cmp(&mtime, &st.st_mtim) <= 0) + goto next_user; if (flags & FL_EDIT_TIMES) { if (readindividualtimes(curprivs, tmpfd) < 0) { errstr(_("Cannot read individual grace times from file.\n")); @@ -16,7 +16,7 @@ msgid "" msgstr "" "Project-Id-Version: quota-tools 4.01\n" "Report-Msgid-Bugs-To: jack@suse.cz\n" -"POT-Creation-Date: 2014-12-02 12:14+0100\n" +"POT-Creation-Date: 2014-12-02 14:02+0100\n" "PO-Revision-Date: 2012-09-10 16:55+0200\n" "Last-Translator: Petr Pisar <petr.pisar@atlas.cz>\n" "Language-Team: Czech <translation-team-cs@lists.sourceforge.net>\n" @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: quota-tools\n" "Report-Msgid-Bugs-To: jack@suse.cz\n" -"POT-Creation-Date: 2014-12-02 12:14+0100\n" +"POT-Creation-Date: 2014-12-02 14:02+0100\n" "PO-Revision-Date: 2010-02-21 13:10+0100\n" "Last-Translator: Michael Bunk <mb@computer-leipzig.com>\n" "Language-Team: German <translation-team-de@lists.sourceforge.net>\n" @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: 1\n" "Report-Msgid-Bugs-To: jack@suse.cz\n" -"POT-Creation-Date: 2014-12-02 12:14+0100\n" +"POT-Creation-Date: 2014-12-02 14:02+0100\n" "PO-Revision-Date: 2003-02-21 22:43+0100\n" "Last-Translator: Jérôme Schell <jerome@myreseau.org>\n" "Language-Team: French <traduc@traduc.org>\n" @@ -1815,8 +1815,8 @@ msgstr "utilisation de %s sur %s [%s] : %s\n" #: quotaon.c:232 msgid "Maybe create new quota files with quotacheck(8)?\n" msgstr "" -"Essayez peut-être de créer un nouveau fichier de quotas avec " -"quotacheck(8) ?\n" +"Essayez peut-être de créer un nouveau fichier de quotas avec quotacheck" +"(8) ?\n" #: quotaon.c:234 msgid "Quota format not supported in kernel.\n" @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: quota 4.01\n" "Report-Msgid-Bugs-To: jack@suse.cz\n" -"POT-Creation-Date: 2014-12-02 12:14+0100\n" +"POT-Creation-Date: 2014-12-02 14:02+0100\n" "PO-Revision-Date: 2014-07-23 22:00+0200\n" "Last-Translator: Jakub Bogusz <qboosh@pld-linux.org>\n" "Language-Team: Polish <translation-team-pl@lists.sourceforge.net>\n" |