summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2015-01-05 15:44:18 +0100
committerJan Kara <jack@suse.cz>2015-01-05 17:12:56 +0100
commit094306bbfdbaacf2b9920b6dc44a6ee155fea1c5 (patch)
tree58cfc19395a7ba71388ded03bd7b814860802f94
parent33160239630e668413bcb915490f604f2870309a (diff)
downloadquota-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.c13
-rw-r--r--common.h5
-rw-r--r--edquota.c30
-rw-r--r--po/cs.po2
-rw-r--r--po/de.po2
-rw-r--r--po/fr.po6
-rw-r--r--po/pl.po2
7 files changed, 54 insertions, 6 deletions
diff --git a/common.c b/common.c
index 8f87202..d11e602 100644
--- a/common.c
+++ b/common.c
@@ -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;
+}
diff --git a/common.h b/common.h
index a42812e..935d6f1 100644
--- a/common.h
+++ b/common.h
@@ -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 */
diff --git a/edquota.c b/edquota.c
index 81ec5e4..fb1d5a8 100644
--- a/edquota.c
+++ b/edquota.c
@@ -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"));
diff --git a/po/cs.po b/po/cs.po
index 7f83f93..d91f8e0 100644
--- a/po/cs.po
+++ b/po/cs.po
@@ -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"
diff --git a/po/de.po b/po/de.po
index 7407965..c91f91f 100644
--- a/po/de.po
+++ b/po/de.po
@@ -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"
diff --git a/po/fr.po b/po/fr.po
index 2c4a41d..ba8f7b9 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -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"
diff --git a/po/pl.po b/po/pl.po
index 664220f..f6fd697 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -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"