aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/backup.c165
-rw-r--r--src/builtin.c10
-rw-r--r--src/config.c26
-rw-r--r--src/dictionary.c11
-rw-r--r--src/directive.c8
-rw-r--r--src/diskio.c6
-rw-r--r--src/exec.c2
-rw-r--r--src/gpg.c7
-rw-r--r--src/job.c2
-rw-r--r--src/lock.c12
-rw-r--r--src/mail.c14
-rw-r--r--src/net.c4
-rw-r--r--src/process.c4
-rw-r--r--src/sql.c4
-rw-r--r--src/timer.c5
-rw-r--r--src/triplet.c17
-rw-r--r--src/txtacc.c16
-rw-r--r--src/verify.c4
-rw-r--r--src/wydawca.c8
-rw-r--r--src/wydawca.h20
21 files changed, 268 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8139849..3b524ba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,71 +1,72 @@
1# This file is part of Wydawca 1# This file is part of Wydawca
2# Copyright (C) 2007, 2009, 2010 Sergey Poznyakoff 2# Copyright (C) 2007, 2009, 2010 Sergey Poznyakoff
3# 3#
4# Wydawca is free software; you can redistribute it and/or modify 4# Wydawca is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option) 6# the Free Software Foundation; either version 3, or (at your option)
7# any later version. 7# any later version.
8# 8#
9# Wydawca is distributed in the hope that it will be useful, 9# Wydawca is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with Wydawca. If not, see <http://www.gnu.org/licenses/>. 15# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
16 16
17sbin_PROGRAMS=wydawca 17sbin_PROGRAMS=wydawca
18wydawca_SOURCES=\ 18wydawca_SOURCES=\
19 backup.c\
19 builtin.c\ 20 builtin.c\
20 builtin.h\ 21 builtin.h\
21 cmdline.h\ 22 cmdline.h\
22 config.c\ 23 config.c\
23 dictionary.c\ 24 dictionary.c\
24 directive.c\ 25 directive.c\
25 diskio.c\ 26 diskio.c\
26 exec.c\ 27 exec.c\
27 gpg.c\ 28 gpg.c\
28 interval.c\ 29 interval.c\
29 job.c\ 30 job.c\
30 lock.c\ 31 lock.c\
31 meta.c\ 32 meta.c\
32 net.c\ 33 net.c\
33 pidfile.c\ 34 pidfile.c\
34 process.c\ 35 process.c\
35 pushd.c\ 36 pushd.c\
36 sql.c\ 37 sql.c\
37 sql.h\ 38 sql.h\
38 tcpwrap.c\ 39 tcpwrap.c\
39 triplet.c\ 40 triplet.c\
40 userprivs.c\ 41 userprivs.c\
41 verify.c\ 42 verify.c\
42 wydawca.c\ 43 wydawca.c\
43 wydawca.h\ 44 wydawca.h\
44 mail.h\ 45 mail.h\
45 mail.c\ 46 mail.c\
46 vtab.c\ 47 vtab.c\
47 null.c\ 48 null.c\
48 timer.c\ 49 timer.c\
49 txtacc.c\ 50 txtacc.c\
50 report.c 51 report.c
51 52
52BUILT_SOURCES=cmdline.h 53BUILT_SOURCES=cmdline.h
53EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk 54EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk
54 55
55SUFFIXES=.opt .c .h 56SUFFIXES=.opt .c .h
56 57
57.opt.h: 58.opt.h:
58 $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@ 59 $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@
59 60
60incdir=$(pkgdatadir)/$(VERSION)/include 61incdir=$(pkgdatadir)/$(VERSION)/include
61inc_DATA = $(PP_SETUP_FILE) 62inc_DATA = $(PP_SETUP_FILE)
62 63
63LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ 64LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
64INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@ 65INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@
65AM_CPPFLAGS= \ 66AM_CPPFLAGS= \
66 -DSYSCONFDIR=\"$(sysconfdir)\"\ 67 -DSYSCONFDIR=\"$(sysconfdir)\"\
67 -DLOCALSTATEDIR=\"$(localstatedir)\"\ 68 -DLOCALSTATEDIR=\"$(localstatedir)\"\
68 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ 69 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
69 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ 70 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
70 -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)" 71 -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)"
71 72
diff --git a/src/backup.c b/src/backup.c
new file mode 100644
index 0000000..312375d
--- /dev/null
+++ b/src/backup.c
@@ -0,0 +1,165 @@
1/* wydawca - automatic release submission daemon
2 Copyright (C) 2011 Sergey Poznyakoff
3
4 Wydawca is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Wydawca is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with wydawca. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "wydawca.h"
18
19char const *simple_backup_suffix = "~";
20
21static const char *
22split_filename (char const *file, char **pdir)
23{
24 const char *p = strrchr (file, '/');
25
26 if (!p)
27 {
28 *pdir = grecs_strdup (".");
29 p = file;
30 }
31 else
32 {
33 size_t len = p - file;
34 char *dir = grecs_malloc (len + 1);
35 memcpy (dir, file, len);
36 dir[len] = 0;
37 *pdir = dir;
38 p++;
39 }
40 return p;
41}
42
43#define MINSUFSIZE 8
44#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
45
46static char *
47get_backup_suffix (char const *file, enum backup_type type)
48{
49 char *dirname;
50 const char *basename;
51 size_t baselen;
52 DIR *dir;
53 struct dirent *ent;
54 char *lastsuf = NULL;
55 size_t lastsuflen = 0;
56 size_t lastsufsize = 0;
57 int carry;
58 char *newsuf;
59 char *q;
60
61 if (type == simple_backups)
62 return grecs_strdup (simple_backup_suffix);
63
64 basename = split_filename (file, &dirname);
65 baselen = strlen (basename);
66 dir = opendir (dirname);
67 if (!dir)
68 {
69 int ec = errno;
70 free (dirname);
71 errno = ec;
72 return NULL;
73 }
74
75 while ((ent = readdir (dir)))
76 {
77 size_t len = strlen (ent->d_name);
78 const char *p;
79 size_t suflen;
80
81 if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen))
82 continue;
83 p = ent->d_name + baselen;
84 suflen = len - baselen;
85 if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' &&
86 (suflen > lastsuflen
87 || (suflen == lastsuflen &&
88 memcmp (p, lastsuf, lastsuflen) > 0)))
89 {
90 carry = 1;
91 for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--)
92 if (*q != '9')
93 carry = 0;
94 q++;
95 if (!ISDIGIT (*q))
96 continue;
97
98 if (suflen > lastsufsize)
99 {
100 lastsufsize = suflen;
101 if (!lastsuf)
102 {
103 if (lastsufsize < MINSUFSIZE)
104 lastsufsize = MINSUFSIZE;
105 lastsuf = grecs_malloc (lastsufsize);
106 }
107 else
108 lastsuf = grecs_realloc (lastsuf, lastsufsize);