| Date: Fri, 1 Sep 2017 15:12:54 +0200
Get rid of mkstemp and use full file name in cache
Diffstat:
config.mk | 2 +-
sacc.c | 36 +++++++++++++++----------------
2 files changed, 18 insertions(+), 20 deletions(-)
--- |
| t@@ -493,7 +493,7 @@ plumbitem(Item *item)
{
char *file, *path, *tag;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP;
- int dest;
+ int n, dest, plumbitem;
if (file = strrchr(item->selector, '/'))
++file;
t@@ -510,36 +510,34 @@ plumbitem(Item *item)
tag = NULL;
}
- if (path[0]) {
- if (tag && !strcmp(tag, path))
- goto cleanup;
+ plumbitem = path[0] ? 0 : 1;
+ if (!path[0]) {
+ clear(&path);
+ if (!tag) {
+ n = snprintf(NULL, 0, "%s/%s", "/tmp/sacc", file);
+ path = xmalloc(++n);
+ snprintf(path, n, "%s/%s", "/tmp/sacc", file);
+ }
+ }
+
+ if (path && (!tag || strcmp(tag, path))) {
if ((dest = open(path, O_WRONLY|O_CREAT|O_EXCL, mode)) < 0) {
uistatus("Can't open destination file %s: %s",
path, strerror(errno));
errno = 0;
goto cleanup;
}
- } else {
- clear(&path);
-
- if (!tag) {
- path = xstrdup("/tmp/sacc/img-XXXXXX");
-
- if ((dest = mkstemp(path)) < 0) {
- uistatus("mkstemp: %s: %s", path, strerror(errno));
- goto cleanup;
- }
- }
+ if (!download(item, dest) || tag)
+ goto cleanup;
}
- if (path && (!download(item, dest) || tag))
- goto cleanup;
-
if (!tag)
item->tag = path;
- plumb(item->tag);
+ if (plumbitem)
+ plumb(item->tag);
+
return;
cleanup:
free(path); |