diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-08-13 12:02:12 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-08-13 12:02:12 +0000 |
commit | 65d71ab4b780a5d18a8146eb4567eb8a9105f4fe (patch) | |
tree | 93dae694b1fd6917176711e467f4f3efab16d1e9 | |
parent | 01dc2086a7b722133ce6d1582e4226942d590cb0 (diff) | |
download | skalibs-65d71ab4b780a5d18a8146eb4567eb8a9105f4fe.tar.xz |
Add atomic_rm_rf and atomic_rm_rf_tmp
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/upgrade.html | 13 | ||||
-rw-r--r-- | package/deps.mak | 10 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/include/skalibs/unix-transactional.h | 3 | ||||
-rw-r--r-- | src/libunixonacid/atomic_rm_rf.c | 9 | ||||
-rw-r--r-- | src/libunixonacid/atomic_rm_rf_tmp.c | 32 | ||||
-rw-r--r-- | src/libunixonacid/mkdir_unique.c | 4 |
8 files changed, 67 insertions, 8 deletions
diff --git a/doc/index.html b/doc/index.html index 9c382b2..2ee91ce 100644 --- a/doc/index.html +++ b/doc/index.html @@ -60,7 +60,7 @@ with a standard C development environment </li> <h3> Download </h3> <ul> - <li> The current released version of skalibs is <a href="skalibs-2.3.6.1.tar.gz">2.3.6.1</a>. </li> + <li> The current released version of skalibs is <a href="skalibs-2.3.7.0.tar.gz">2.3.7.0</a>. </li> <li> Alternatively, you can checkout a copy of the skalibs git repository: <pre> git clone git://git.skarnet.org/skalibs </pre> </li> </ul> diff --git a/doc/upgrade.html b/doc/upgrade.html index 381aa8a..6058dda 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,13 +18,18 @@ <h1> What has changed in skalibs </h1> +<h2> in 2.3.7.0 </h2> + +<ul> + <li> New functions: <tt>atomic_rm_rf()</tt>, <tt>atomic_rm_rf_tmp()</tt>. </li> +</ul> + <h2> in 2.3.6.1 </h2> <ul> <li> No functional changes. </li> </ul> - <h2> in 2.3.6.0 </h2> <ul> @@ -46,13 +51,13 @@ <h2> in 2.3.5.0 </h2> <ul> - <li> New functions: bitarray_count(), openwritevnclose_at() </li> + <li> New functions: <tt>bitarray_count()</tt>, <tt>openwritevnclose_at()</tt> </li> </ul> <h2> in 2.3.4.0 </h2> <ul> - <li> New function: stat_at() </li> + <li> New function: <tt>stat_at()</tt> </li> <li> The rest of the changes are bugfixes or QoL. </li> </ul> @@ -65,7 +70,7 @@ <h2> in 2.3.2.0 </h2> <ul> - <li> New macro: gid0_scan() </li> + <li> New macro: <tt>gid0_scan()</tt> </li> </ul> <h2> in 2.3.1.3 </h2> diff --git a/package/deps.mak b/package/deps.mak index 3a73767..b668d59 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -21,13 +21,16 @@ src/include/skalibs/djbtime.h: src/include/skalibs/config.h src/include/skalibs/ src/include/skalibs/djbunix.h: src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/gccattributes.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h +src/include/skalibs/error.h: src/include/skalibs/gccattributes.h src/include/skalibs/fmtscan.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h src/include/skalibs/functypes.h: src/include/skalibs/siovec.h src/include/skalibs/genalloc.h: src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/genset.h: src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h: src/include/skalibs/functypes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h +src/include/skalibs/gidstuff.h: src/include/skalibs/uint32.h src/include/skalibs/iobuffer.h: src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/iopause.h: src/include/skalibs/tai.h +src/include/skalibs/ip46.h: src/include/skalibs/bytestr.h src/include/skalibs/fmtscan.h src/include/skalibs/socket.h src/include/skalibs/tai.h src/include/skalibs/uint16.h src/include/skalibs/kolbak.h: src/include/skalibs/unixmessage.h src/include/skalibs/lolstdio.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/strerr2.h src/include/skalibs/md5.h: src/include/skalibs/uint32.h @@ -51,6 +54,10 @@ src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/surf.h: src/include/skalibs/uint32.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h +src/include/skalibs/uint.h: src/include/skalibs/uint32.h +src/include/skalibs/uint16.h: src/include/skalibs/uint64.h +src/include/skalibs/uint32.h: src/include/skalibs/uint64.h +src/include/skalibs/ulong.h: src/include/skalibs/uint64.h src/include/skalibs/unirandom.h: src/include/skalibs/buffer.h src/include/skalibs/surf.h src/include/skalibs/unirandomdev.h: src/include/skalibs/unirandom.h src/include/skalibs/unirandomegd.h: src/include/skalibs/unirandom.h @@ -60,6 +67,7 @@ src/include/skalibs/unix-transactional.h: src/include/skalibs/siovec.h src/inclu src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h src/include/skalibs/unixmessage.h: src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/siovec.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/unixonacid.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h +src/include/skalibs/ushort.h: src/include/skalibs/uint16.h src/include/skalibs/webipc.h: src/include/skalibs/djbunix.h src/include/skalibs/tai.h src/libdatastruct/avlnode-internal.h: src/include/skalibs/avlnode.h src/librandom/random-internal.h: src/include/skalibs/gccattributes.h src/include/skalibs/rrandom.h src/include/skalibs/surf.h src/include/skalibs/unirandom.h @@ -711,6 +719,8 @@ src/libstddjb/wait_reap.o src/libstddjb/wait_reap.lo: src/libstddjb/wait_reap.c src/libstddjb/waitn.o src/libstddjb/waitn.lo: src/libstddjb/waitn.c src/include/skalibs/djbunix.h src/libstddjb/waitn_reap.o src/libstddjb/waitn_reap.lo: src/libstddjb/waitn_reap.c src/include/skalibs/djbunix.h src/libstddjb/waitpid_nointr.o src/libstddjb/waitpid_nointr.lo: src/libstddjb/waitpid_nointr.c src/include/skalibs/djbunix.h +src/libunixonacid/atomic_rm_rf.o src/libunixonacid/atomic_rm_rf.lo: src/libunixonacid/atomic_rm_rf.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h +src/libunixonacid/atomic_rm_rf_tmp.o src/libunixonacid/atomic_rm_rf_tmp.lo: src/libunixonacid/atomic_rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h src/libunixonacid/bufalloc_timed_flush.o src/libunixonacid/bufalloc_timed_flush.lo: src/libunixonacid/bufalloc_timed_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_fill.o src/libunixonacid/buffer_timed_fill.lo: src/libunixonacid/buffer_timed_fill.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_flush.o src/libunixonacid/buffer_timed_flush.lo: src/libunixonacid/buffer_timed_flush.c src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h diff --git a/package/info b/package/info index 8845d15..8c8825f 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=skalibs -version=2.3.6.1 +version=2.3.7.0 category=prog package_macro_name=SKALIBS diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h index e1c8955..beb27b4 100644 --- a/src/include/skalibs/unix-transactional.h +++ b/src/include/skalibs/unix-transactional.h @@ -40,6 +40,9 @@ extern unsigned int openwritenclose_at (int, char const *, char const *, unsigne extern unsigned int openwritevnclose_at (int, char const *, siovec_t const *, unsigned int) ; extern int mkdir_unique (stralloc *, char const *, unsigned int) ; +extern int atomic_rm_rf (char const *) ; +extern int atomic_rm_rf_tmp (char const *, stralloc *) ; + typedef struct dirdescriptor_s dirdescriptor_t, *dirdescriptor_t_ref ; struct dirdescriptor_s diff --git a/src/libunixonacid/atomic_rm_rf.c b/src/libunixonacid/atomic_rm_rf.c new file mode 100644 index 0000000..b7f157b --- /dev/null +++ b/src/libunixonacid/atomic_rm_rf.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include <skalibs/skamisc.h> +#include <skalibs/unix-transactional.h> + +int atomic_rm_rf (char const *filename) +{ + return atomic_rm_rf_tmp(filename, &satmp) ; +} diff --git a/src/libunixonacid/atomic_rm_rf_tmp.c b/src/libunixonacid/atomic_rm_rf_tmp.c new file mode 100644 index 0000000..8be5189 --- /dev/null +++ b/src/libunixonacid/atomic_rm_rf_tmp.c @@ -0,0 +1,32 @@ +/* ISC license. */ + +#include <errno.h> +#include <stdio.h> +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> +#include <skalibs/random.h> +#include <skalibs/unix-transactional.h> + +int atomic_rm_rf_tmp (char const *filename, stralloc *tmp) +{ + unsigned int tmpbase = tmp->len ; + unsigned int start ; + if (!stralloc_cats(tmp, ".skalibs-rmrf-") + || !stralloc_cats(tmp, filename)) return -1 ; + start = tmp->len ; + for (;;) + { + if (random_sauniquename(tmp, 64) < 0) goto err ; + if (!stralloc_0(tmp)) goto err ; + if (!rename(filename, tmp->s + tmpbase)) break ; + if (errno != EEXIST && errno != ENOTEMPTY) goto err ; + tmp->len = start ; + } + if (rm_rf_in_tmp(tmp, tmpbase) < 0) goto err ; + tmp->len = tmpbase ; + return 0 ; + +err: + tmp->len = tmpbase ; + return -1 ; +} diff --git a/src/libunixonacid/mkdir_unique.c b/src/libunixonacid/mkdir_unique.c index 523ecef..efc74cc 100644 --- a/src/libunixonacid/mkdir_unique.c +++ b/src/libunixonacid/mkdir_unique.c @@ -10,8 +10,8 @@ int mkdir_unique (stralloc *sa, char const *fn, unsigned int mode) unsigned int base = sa->len ; int wasnull = !sa->s ; if (!stralloc_cats(sa, fn)) return 0 ; - if (!stralloc_cats(sa, "/mkdir_unique")) goto fail ; - if (random_sauniquename(sa, 8) < 0) goto fail ; + if (!stralloc_cats(sa, "/mkdir_unique:")) goto fail ; + if (random_sauniquename(sa, 64) < 0) goto fail ; if (!stralloc_0(sa)) goto fail ; if (mkdir(sa->s + base, mode) < 0) goto fail ; sa->len-- ; |