diff options
author | waker <wakeroid@gmail.com> | 2011-06-23 20:40:20 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-06-23 20:40:20 +0200 |
commit | 2e702e0996c847d97d1f514d729c9f6932889804 (patch) | |
tree | c68482d751f0407518a20750e23dcec9e0f59d8f | |
parent | 97c4bf5ba413a120e6277c73e82b1d150c459592 (diff) |
converter: automatically create directory structure
artwork: minor readability fix in check_dir
-rw-r--r-- | plugins/artwork/artwork.c | 3 | ||||
-rw-r--r-- | plugins/converter/converter.c | 33 |
2 files changed, 34 insertions, 2 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 7f56b870..d603c06d 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -186,8 +186,7 @@ check_dir (const char *dir, mode_t mode) } if (slash) *slash = '/'; - } - while (slash); + } while (slash); free (tmp); return 1; } diff --git a/plugins/converter/converter.c b/plugins/converter/converter.c index 04a97777..39604785 100644 --- a/plugins/converter/converter.c +++ b/plugins/converter/converter.c @@ -693,6 +693,34 @@ get_output_path (DB_playItem_t *it, const char *outfolder, const char *outfile, trace ("converter output file is '%s'\n", out); } +static int +check_dir (const char *dir, mode_t mode) +{ + char *tmp = strdup (dir); + char *slash = tmp; + struct stat stat_buf; + do + { + slash = strstr (slash+1, "/"); + if (slash) + *slash = 0; + if (-1 == stat (tmp, &stat_buf)) + { + trace ("creating dir %s\n", tmp); + if (0 != mkdir (tmp, mode)) + { + trace ("Failed to create %s (%d)\n", tmp, errno); + free (tmp); + return 0; + } + } + if (slash) + *slash = '/'; + } while (slash); + free (tmp); + return 1; +} + int convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int output_bps, int output_is_float, int preserve_folder_structure, const char *root_folder, ddb_encoder_preset_t *encoder_preset, ddb_dsp_preset_t *dsp_preset, int *abort) { if (deadbeef->pl_get_item_duration (it) <= 0) { @@ -703,6 +731,11 @@ convert (DB_playItem_t *it, const char *outfolder, const char *outfile, int outp return -1; } + if (!check_dir (outfolder, 0755)) { + fprintf (stderr, "converter: failed to create output folder: %s\n", outfolder); + return -1; + } + int err = -1; FILE *enc_pipe = NULL; FILE *temp_file = NULL; |