diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-12 18:44:32 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-12 18:44:32 +0200 |
commit | 742ed57ac88f52434f966a0b44dc8bdd9dd9983b (patch) | |
tree | e625fae5ee9594960c46df57f2b235cb4a82a594 | |
parent | 8df3ab3b50d6ca61859f6c8f1d49913276a4d32d (diff) |
sfeed_frames: make content filename more unique: use UNIX timestamp in title
this makes sure if an item has the same title but is posted or updated at a
different time it will not overwrite the file.
-rw-r--r-- | sfeed_frames.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c index 9431842..288e5e3 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -144,19 +144,21 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) line[--linelen] = '\0'; if (!parseline(line, fields)) break; - /* write content */ - if (!normalizepath(fields[FieldTitle], name, sizeof(name))) - continue; - r = snprintf(filepath, sizeof(filepath), "%s/%s.html", dirpath, name); - if (r == -1 || (size_t)r >= sizeof(filepath)) - errx(1, "snprintf: path truncation: '%s/%s.html'", dirpath, name); parsedtime = 0; strtotime(fields[FieldUnixTimestamp], &parsedtime); - if (!(tm = localtime(&parsedtime))) err(1, "localtime"); + if (!normalizepath(fields[FieldTitle], name, sizeof(name))) + continue; + + r = snprintf(filepath, sizeof(filepath), "%s/%s-%lld.html", + dirpath, name, (long long)parsedtime); + if (r == -1 || (size_t)r >= sizeof(filepath)) + errx(1, "snprintf: path truncation: '%s/%s-%lld.html'", + dirpath, name, (long long)parsedtime); + /* content file doesn't exist yet and has error? */ if ((fd = open(filepath, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1) { |