From 4a229a3bbdc13c3ce15b8f7b161a5a454535bd36 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Sun, 13 Oct 2019 14:43:13 +0200 Subject: [PATCH] Fixing #39 --- README.md | 6 ++++-- config.h | 2 +- src/error.c | 10 +++++++--- src/error.h | 2 +- src/helper.c | 24 ++++++++++++++++++++---- src/helper.h | 2 +- src/main.c | 2 +- src/utils.c | 11 ++++++----- src/utils.h | 2 +- 9 files changed, 42 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6260065..5cb4b57 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Caesium CommandLineTools -##### caesium-clt - v0.13.0-beta (build 20190928) - Copyright © Matteo Paonessa, 2018. All Rights Reserved. +##### caesium-clt - v0.13.1-beta (build 20191013) - Copyright © Matteo Paonessa, 2019. All Rights Reserved. [![Build Status](https://travis-ci.org/Lymphatus/caesium-clt.svg?branch=master)](https://travis-ci.org/Lymphatus/caesium-clt) ---------- @@ -15,7 +15,6 @@ ###### TESTED PLATFORMS * Mac OS X Mojave (v10.14.4) * Ubuntu 19.04 -* Windows 10 ---------- @@ -42,6 +41,8 @@ See INSTALL.md for more details. Note that this may end up building a large set of files to be compressed and should be used carefully. - `-S, --keep-structure` If the input is a folder, and the `-R` option is set, caesiumclt will compress all the files keeping the original folder structure. +- `-O, --overwrite` + Sets the overwrite policy: `all` will overwrite any existing file, `prompt` will ask each time before overwriting, `bigger` will overwrite bigger files only, and `none` will silently skip existing files. - `-d, --dry-run` If this option is set, no files will be compressed, but the entire process will just be simulated. Useful for checking if all the files will be correctly handled. @@ -95,6 +96,7 @@ $ caesiumclt -q 0 -RS -o ~/output/ ~/Pictures ###### CHANGELOG * 0.13.0-beta - Bugfix +* 0.13.0-beta - Bugfix * 0.12.1-beta - Bugfix * 0.12.0-beta - Resizing (experimental) * 0.11.0-beta - Fixing paths issues and dry-run option diff --git a/config.h b/config.h index 8a31517..74642bf 100644 --- a/config.h +++ b/config.h @@ -1,4 +1,4 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 13 -#define VERSION_PATCH 0 +#define VERSION_PATCH 1 diff --git a/src/error.c b/src/error.c index 1aab5df..e5f94da 100644 --- a/src/error.c +++ b/src/error.c @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -58,13 +58,17 @@ const char *get_error_message(int code) { case 11: return "-S has no effect without -R."; case 12: - return "Cannot set output folder inside the input one"; + return "Cannot set output folder inside the input one."; case 13: return "Scale factor must be between (0, 1.0]. Setting it to 1.0."; case 14: return "Scale factor parsing error."; case 15: - return "Overwrite policy value is invalid. Using 'all'."; + return "Overwrite policy value is invalid. Using 'bigger'."; + case 16: + return "Cannot get the full output path."; + case 17: + return "Cannot create the output folder."; default: return "Unrecognized error."; diff --git a/src/error.h b/src/error.h index b1a83c6..7445aa1 100644 --- a/src/error.h +++ b/src/error.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/helper.c b/src/helper.c index a8be985..14ca370 100644 --- a/src/helper.c +++ b/src/helper.c @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -68,7 +69,23 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options) { #ifdef _WIN32 _fullpath(parameters.output_folder, opts.optarg, MAX_PATH); #else - realpath(opts.optarg, parameters.output_folder); + char* computedPath = realpath(opts.optarg, parameters.output_folder); + if (computedPath == NULL) { + //Folder does not exists and may just fail on some systems, like Docker Alpine + if (errno == 2) { + if (mkpath(opts.optarg) == 0) { + computedPath = realpath(opts.optarg, parameters.output_folder); + if (computedPath == NULL) { + //Just throw an error here + display_error(ERROR, 16); + } + } else { + display_error(ERROR, 17); + } + } else { + display_error(ERROR, 16); + } + } #endif } int pathlen = (int)strlen(parameters.output_folder); @@ -155,7 +172,6 @@ cclt_options parse_arguments(char **argv, cs_image_pars *options) { } snprintf(parameters.input_folder, strlen(resolved_path) + 1, "%s", resolved_path); - int count = 0; scan_folder(resolved_path, ¶meters, parameters.recursive); if (parameters.files_count == 0) { display_error(WARNING, 3); @@ -242,7 +258,7 @@ int start_compression(cclt_options *options, cs_image_pars *parameters) { mkpath(output_full_folder); } - //Calculating the total input file size, ignoring of we are going to skip them later + //Calculating the total input file size, ignoring if we are going to skip them later file_size = get_file_size(options->input_files[i]); if (file_size == 0) { //We could not open the file diff --git a/src/helper.h b/src/helper.h index a84f172..69ffaf7 100644 --- a/src/helper.h +++ b/src/helper.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main.c b/src/main.c index cf07e20..041f6f4 100755 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/utils.c b/src/utils.c index b3056f9..9ae1f0e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef _WIN32 #include #endif @@ -40,10 +41,10 @@ void print_help() "\t-q, --quality\t\tset output file quality between [0-100], 0 for optimization\n" "\t-e, --exif\t\tkeeps EXIF info during compression\n" "\t-o, --output\t\toutput folder\n" - "\t-s, --scale\t\tscale the image. Allowed formats are [.x, 0.x, n/d, xx%%].\n\t\t\t\tMust be > 0 and <= 1.0.\n" + "\t-s, --scale\t\t[EXPERIMENTAL] scale the image. Allowed formats are [.x, 0.x, n/d, xx%%].\n\t\t\t\tMust be > 0 and <= 1.0.\n" "\t-R, --recursive\t\tif input is a folder, scan subfolders too\n" "\t-S, --keep-structure\tkeep the folder structure, use with -R\n" - "\t-O, --overwrite\t\tOverwrite policy: all, none, prompt, bigger. Default is all.\n" + "\t-O, --overwrite\t\tOverwrite policy: all, none, prompt, bigger. Default is bigger.\n" "\t-d, --dry-run\t\tdo not really compress files but just show output paths\n" "\t-h, --help\t\tdisplay this help and exit\n" "\t-v, --version\t\toutput version information and exit\n\n"); @@ -116,7 +117,7 @@ int mkpath(const char *pathname) return 0; } #else - if (mkdir(pathname, 0777) == 0) { + if (mkdir(pathname, 0755) == 0) { return 0; } #endif @@ -276,7 +277,7 @@ overwrite_policy parse_overwrite_policy(const char* overwrite_string) return all; } display_error(WARNING, 15); - return all; + return bigger; } diff --git a/src/utils.h b/src/utils.h index 818d72e..f9fd685 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 Matteo Paonessa + * Copyright 2019 Matteo Paonessa * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at