From 5153780ac2d83cd46113ca1bfd1f7182e748f18e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 7 Jun 2010 21:55:55 +0200 Subject: --caption-path: Autocreate caption directories if they don't exist --- ChangeLog | 1 + src/imlib.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 654f62e..a879082 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ git HEAD have no use for these shortcuts) is growing. * Draw a nice little message when in caption editing mode with empty caption (to indicate that caption editing is actually active) + * caption mode: Automatically create caption directory if it doesn't exist Sat Jun 5 21:35:25 CEST 2010 Daniel Friesel filename, '/'); if (s) { dir = estrdup(file->filename); @@ -677,6 +678,20 @@ char *build_caption_filename(feh_file * file) } else { dir = estrdup("."); } + + caption_dir = estrjoin("/", dir, opt.caption_path, NULL); + + D(4, ("dir %s, cp %s, cdir %s\n", dir, opt.caption_path, caption_dir)) + + if (stat(caption_dir, &cdir_stat) == -1) { + if (mkdir(caption_dir, 0755) == -1) + eprintf("Failed to create caption directory %s:", caption_dir); + } else if (!S_ISDIR(cdir_stat.st_mode)) + eprintf("Caption directory (%s) exists, but is not a directory.", + caption_dir); + + free(caption_dir); + caption_filename = estrjoin("", dir, "/", opt.caption_path, "/", file->name, ".txt", NULL); free(dir); return caption_filename; -- cgit v1.2.3