summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-19 18:40:23 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-19 19:19:29 +0100
commit8eebf6ad553adb22d7ea5d291de0b0da38606f4d (patch)
tree89c27d23acf69e54768416e696cec82a51b78078 /src/shared
parent668c965af4e803f460925dc616f328ed274d1f3a (diff)
util: when creating temporary filename for atomic creation of files, add an extra "#" to the name
That way, we have a simple, somewhat reliable way to detect such temporary files, by simply checking if they start with ".#".
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index dbae55fe38..5f18d34c3d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6992,18 +6992,18 @@ int tempfn_xxxxxx(const char *p, char **ret) {
* /foo/bar/waldo
*
* Into this:
- * /foo/bar/.waldoXXXXXX
+ * /foo/bar/.#waldoXXXXXX
*/
fn = basename(p);
if (!filename_is_valid(fn))
return -EINVAL;
- t = new(char, strlen(p) + 1 + 6 + 1);
+ t = new(char, strlen(p) + 2 + 6 + 1);
if (!t)
return -ENOMEM;
- strcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), "."), fn), "XXXXXX");
+ strcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), fn), "XXXXXX");
*ret = path_kill_slashes(t);
return 0;
@@ -7023,18 +7023,18 @@ int tempfn_random(const char *p, char **ret) {
* /foo/bar/waldo
*
* Into this:
- * /foo/bar/.waldobaa2a261115984a9
+ * /foo/bar/.#waldobaa2a261115984a9
*/
fn = basename(p);
if (!filename_is_valid(fn))
return -EINVAL;
- t = new(char, strlen(p) + 1 + 16 + 1);
+ t = new(char, strlen(p) + 2 + 16 + 1);
if (!t)
return -ENOMEM;
- x = stpcpy(stpcpy(mempcpy(t, p, fn - p), "."), fn);
+ x = stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), fn);
u = random_u64();
for (i = 0; i < 16; i++) {
@@ -7059,14 +7059,14 @@ int tempfn_random_child(const char *p, char **ret) {
/* Turns this:
* /foo/bar/waldo
* Into this:
- * /foo/bar/waldo/.3c2b6219aa75d7d0
+ * /foo/bar/waldo/.#3c2b6219aa75d7d0
*/
- t = new(char, strlen(p) + 2 + 16 + 1);
+ t = new(char, strlen(p) + 3 + 16 + 1);
if (!t)
return -ENOMEM;
- x = stpcpy(stpcpy(t, p), "/.");
+ x = stpcpy(stpcpy(t, p), "/.#");
u = random_u64();
for (i = 0; i < 16; i++) {