diff --git a/lib/api.h b/lib/api.h index 63beb787..3cb89400 100644 --- a/lib/api.h +++ b/lib/api.h @@ -27,6 +27,7 @@ #include #include "cfg.h" +#include "cfg-funcs.h" #include "cmdline.h" #include "config.h" #include "session.h" diff --git a/lib/cfg.c b/lib/cfg-funcs.h similarity index 62% rename from lib/cfg.c rename to lib/cfg-funcs.h index 4724f47d..c2e4f000 100644 --- a/lib/cfg.c +++ b/lib/cfg-funcs.h @@ -22,20 +22,25 @@ * Hosted on http://github.com/sahib/rmlint **/ -#include -#include -#include +#ifndef RM_CFG_FUNCS_H +#define RM_CFG_FUNCS_H -#include "cfg.h" +#include // memset +#include // bool, true, false +#include // PATH_MAX (maybe) +#include // G_MAXUINT64, g_strdup, G_LOG_LEVEL_INFO, g_slist_free_full -static void rm_path_free(RmPath *rmpath) { - free(rmpath->path); - g_slice_free(RmPath, rmpath); -} +#include "config.h" // RM_DEFAULT_DIGEST, PATH_MAX (maybe), RmOff +#include "cfg.h" // RmCfg +#include "pathtricia.h" // rm_trie_init +#include "path-funcs.h" // rm_path_free, rm_path_is_valid, rm_path_is_json, rm_path_prepend /* Options not specified by commandline get a default option - * this is usually called before rm_cmd_parse_args */ +static INLINE void rm_cfg_set_default(RmCfg *cfg) { + g_assert(cfg); + /* Set everything to 0 at first, * only non-null options are listed below. */ @@ -87,8 +92,8 @@ void rm_cfg_set_default(RmCfg *cfg) { * 32k => 15.8 seconds */ cfg->read_buf_len = 16 * 1024; - cfg->total_mem = (RmOff)1024 * 1024 * 1024; - cfg->sweep_size = 1024 * 1024 * 1024; + cfg->total_mem = 1024L * 1024 * 1024; + cfg->sweep_size = 1024L * 1024 * 1024; cfg->sweep_count = 1024 * 16; cfg->skip_start_factor = 0.0; @@ -103,46 +108,64 @@ void rm_cfg_set_default(RmCfg *cfg) { rm_trie_init(&cfg->file_trie); } -guint rm_cfg_add_path(RmCfg *cfg, bool is_prefd, const char *path) { - int rc = 0; - -#if HAVE_FACCESSAT - rc = faccessat(AT_FDCWD, path, R_OK, AT_EACCESS); -#else - rc = access(path, R_OK); -#endif - - if(rc != 0) { - rm_log_warning_line(_("Can't open directory or file \"%s\": %s"), path, - strerror(errno)); - return 0; - } - - char *real_path = realpath(path, NULL); - if(real_path == NULL) { - rm_log_warning_line(_("Can't get real path for directory or file \"%s\": %s"), - path, strerror(errno)); - return 0; +static INLINE +bool rm_cfg_prepend_json( + RmCfg *const cfg, + const char *const path +) { + g_assert(cfg); + char *real_path; + if(rm_path_is_valid(path, &real_path) && rm_path_is_json(real_path)) { + rm_path_prepend( + &cfg->json_paths, + real_path, + cfg->path_count++, + false /* not preferred */ + ); + return true; } + return false; +} - RmPath *rmpath = g_slice_new(RmPath); - rmpath->path = real_path; - rmpath->is_prefd = is_prefd; - rmpath->idx = cfg->path_count++; - rmpath->treat_as_single_vol = strncmp(path, "//", 2) == 0; - - if(cfg->replay && g_str_has_suffix(rmpath->path, ".json")) { - cfg->json_paths = g_slist_prepend(cfg->json_paths, rmpath); - return 1; +#define PREPEND_TO(list) \ + rm_path_prepend( \ + &(list), \ + real_path, \ + index, \ + preferred \ + ) + +static INLINE +bool rm_cfg_prepend_path( + RmCfg *const cfg, + const char *const path, + const unsigned int index, + const bool replay, + const bool preferred +) { + g_assert(cfg); + char *real_path; + if(rm_path_is_valid(path, &real_path)) { + if(replay && rm_path_is_json(path)) { + PREPEND_TO(cfg->json_paths); + } else { + PREPEND_TO(cfg->paths); + ++(cfg->path_count); + } + return true; } - - cfg->paths = g_slist_prepend(cfg->paths, rmpath); - return 1; + return false; } -void rm_cfg_free_paths(RmCfg *cfg) { +#undef PREPEND_TO + +static INLINE +void rm_cfg_free_paths(RmCfg *const cfg) { + g_assert(cfg); g_slist_free_full(cfg->paths, (GDestroyNotify)rm_path_free); cfg->paths = NULL; g_slist_free_full(cfg->json_paths, (GDestroyNotify)rm_path_free); cfg->json_paths = NULL; } + +#endif /* end of include guard */ diff --git a/lib/cfg.h b/lib/cfg.h index 5b1e7e4a..63e2cd3e 100644 --- a/lib/cfg.h +++ b/lib/cfg.h @@ -22,29 +22,15 @@ * Hosted on http://github.com/sahib/rmlint **/ -#ifndef RM_SETTINGS_H -#define RM_SETTINGS_H +#ifndef RM_CFG_H +#define RM_CFG_H -#include +#include // bool +#include // gboolean, gdouble, gint, GSList, guint -#include "checksum.h" -#include "pathtricia.h" -#include "utilities.h" - -/* Struct for paths passed to rmlint from command line (or stdin) */ -typedef struct RmPath { - /* the RealPath of the passed string */ - char *path; - - /* index number (command line order) */ - guint idx; - - /* whether path was tagged as preferred path */ - bool is_prefd; - - /* whether to treat all files under path as one filesystem */ - bool treat_as_single_vol; -} RmPath; +#include "config.h" // RmOff +#include "pathtricia.h" // RmTrie +#include "checksum.h" // RmDigestType /* Storage struct for all options settable in cmdline. */ typedef struct RmCfg { @@ -87,7 +73,6 @@ typedef struct RmCfg { gboolean progress_enabled; gboolean list_mounts; gboolean replay; - gboolean read_stdin; gboolean read_stdin0; gboolean no_backup; @@ -115,16 +100,13 @@ typedef struct RmCfg { * * + To record a unique index for each path supplied by the * user; a path's index represents the number of paths that - * were already processed. This is always the case. + * were already processed. This is the case DURING the + * processing of user-input options (such as '--replay'). * - * + To provide quick access to the length of its associated - * RmCfg::paths list. This is only the case when NOT running - * in "--replay" mode; when running in "--replay" mode, it - * just represents the total number of paths that have been - * supplied by the user, i.e., the sums of the lengths of - * the associated lists RmCfg::{paths,json_paths}, which is - * not meant to be a useful number to know, and is simply a - * byproduct of calculating path indicies. + * + To provide quick access to the length of its associated + * RmCfg::paths list. This is the case AFTER the processing + * of user-input options (including during the processing of + * non-option paths from the command line or stdin). */ guint path_count; @@ -186,19 +168,4 @@ typedef struct RmCfg { } RmCfg; -/** - * @brief Reset RmCfg to default cfg and all other vars to 0. - */ -void rm_cfg_set_default(RmCfg *cfg); - -/** - * @brief check and add a path to cfg->paths. - */ -guint rm_cfg_add_path(RmCfg *cfg, bool is_prefd, const char *path); - -/** - * @brief free all data associated with cfg->paths. - */ -void rm_cfg_free_paths(RmCfg *cfg); - #endif /* end of include guard */ diff --git a/lib/cmdline.c b/lib/cmdline.c index 088b6318..52b13005 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -39,6 +39,7 @@ #include #include +#include "cfg-funcs.h" #include "cmdline.h" #include "formats.h" #include "hash-utility.h" @@ -49,6 +50,7 @@ #include "traverse.h" #include "treemerge.h" #include "utilities.h" +#include "path.h" /* define paranoia levels */ static const RmDigestType RM_PARANOIA_LEVELS[] = {RM_DIGEST_METRO, @@ -284,7 +286,7 @@ static RmOff rm_cmd_size_string_to_bytes(const char *size_spec, GError **error) g_set_error(error, RM_ERROR_QUARK, 0, _("This does not look like a number")); return 0; } else if(decimal < 0) { - g_set_error(error, RM_ERROR_QUARK, 0, _("Negativ sizes are no good idea")); + g_set_error(error, RM_ERROR_QUARK, 0, _("A size must be non-negative")); return 0; } else if(*format) { format = g_strstrip(format); @@ -358,31 +360,6 @@ static GLogLevelFlags VERBOSITY_TO_LOG_LEVEL[] = {[0] = G_LOG_LEVEL_CRITICAL, [3] = G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO, [4] = G_LOG_LEVEL_DEBUG}; -static bool rm_cmd_read_paths_from_stdin(RmSession *session, bool is_prefd, - bool null_separated) { - char delim = null_separated ? 0 : '\n'; - - size_t buf_len = PATH_MAX; - char *path_buf = malloc(buf_len * sizeof(char)); - - bool all_paths_read = true; - - int path_len; - - /* Still read all paths on errors, so the user knows all paths that failed */ - while((path_len = getdelim(&path_buf, &buf_len, delim, stdin)) >= 0) { - if(path_len > 0) { - /* replace returned delimiter with null */ - if (path_buf[path_len - 1] == delim) { - path_buf[path_len - 1] = 0; - } - all_paths_read &= rm_cfg_add_path(session->cfg, is_prefd, path_buf); - } - } - - free(path_buf); - return all_paths_read; -} static bool rm_cmd_parse_output_pair(RmSession *session, const char *pair, GError **error) { @@ -1096,12 +1073,26 @@ static gboolean rm_cmd_parse_rankby(_UNUSED const char *option_name, } static gboolean rm_cmd_parse_replay(_UNUSED const char *option_name, - const gchar *json_path, RmSession *session, - _UNUSED GError **error) { + const gchar *path, RmSession *session, + GError **error) { + g_assert(session); + g_assert(session->cfg); session->cfg->replay = true; session->cfg->cache_file_structs = true; - rm_cfg_add_path(session->cfg, false, json_path); - return true; + + if(rm_cfg_prepend_json(session->cfg, path)) { + return true; + } + + g_assert(error); + g_assert(*error == NULL); + + g_set_error( + error, RM_ERROR_QUARK, 0, + _("Failed to include this replay file: %s"), path + ); + + return false; } static gboolean rm_cmd_parse_equal(_UNUSED const char *option_name, @@ -1167,42 +1158,128 @@ static bool rm_cmd_set_cmdline(RmCfg *cfg, int argc, char **argv) { return true; } -static bool rm_cmd_set_paths(RmSession *session, char **paths) { - bool is_prefd = false; - bool all_paths_valid = true; - bool stdin_paths_preferred = false; +typedef struct RmCmdSetPathVars { + RmCfg *const cfg; + char **const paths; + unsigned int index; + bool is_prefd; + bool read_stdin; + bool stdin_paths_preferred; + const bool null_separated; + bool all_paths_valid; +} RmCmdSetPathVars; + +static INLINE +void rm_cmd_set_paths_from_cmdline( + RmCmdSetPathVars *const v, + const bool replay +) { + g_assert(v); + g_assert(v->paths); + + for(char *path, **list = v->paths; (path = *list); ++list) { + if(/* path is "-" */ path[0] == '-' && path[1] == 0) { + v->read_stdin = true; + v->stdin_paths_preferred = v->is_prefd; + } else if(/* path is "//" */ path[0] == '/' && path[1] == '/' && path[2] == 0) { + v->is_prefd = !v->is_prefd; + } else { + v->all_paths_valid &= rm_cfg_prepend_path( + v->cfg, path, v->index++, replay, v->is_prefd + ); + } + g_free(path); + } + g_free(v->paths); +} + +static INLINE +bool rm_cmd_set_paths_from_stdin( + RmCmdSetPathVars *const v, + const bool replay +) { + g_assert(v); + g_assert(v->cfg); - RmCfg *cfg = session->cfg; + RmCfg *const cfg = v->cfg; + const bool is_prefd = v->stdin_paths_preferred; - /* Check the directory to be valid */ - for(int i = 0; paths && paths[i]; ++i) { - if(strcmp(paths[i], "-") == 0) { - cfg->read_stdin = true; - /* remember whether to treat stdin paths as preferred paths */ - stdin_paths_preferred = is_prefd; - } else if(strcmp(paths[i], "//") == 0) { - /* the '//' separator separates non-preferred paths from preferred */ - is_prefd = !is_prefd; - } else { - all_paths_valid &= rm_cfg_add_path(cfg, is_prefd, paths[i]); + char delim = v->null_separated ? 0 : '\n'; + + size_t buf_len = PATH_MAX; + char *path_buf = malloc(buf_len); + if(!path_buf) { + rm_log_perror(_("Failed to allocate memory")); + return false; + } + + int path_len; + + /* Still read all paths on errors, so the user knows all paths that failed */ + while((path_len = getdelim(&path_buf, &buf_len, delim, stdin)) >= 0) { + if(path_len > 0) { + /* replace returned delimiter with null */ + if(path_buf[path_len - 1] == delim) { + path_buf[path_len - 1] = 0; + } + v->all_paths_valid &= rm_cfg_prepend_path( + cfg, path_buf, v->index++, replay, is_prefd + ); } } - g_strfreev(paths); + if(ferror(stdin)) { + rm_log_perror(_("Failed to read stdin")) + return false; + } - if(cfg->read_stdin || cfg->read_stdin0) { - /* option '-' means read paths from stdin */ - all_paths_valid &= - rm_cmd_read_paths_from_stdin(session, stdin_paths_preferred, cfg->read_stdin0); + free(path_buf); + return true; +} + +#define PROCESS_PATHS(replay) \ + if(paths) { \ + rm_cmd_set_paths_from_cmdline(&v, (replay)); \ + } \ + if(v.read_stdin) { \ + if(!rm_cmd_set_paths_from_stdin(&v, (replay))) { \ + rm_log_error_line(_("Could not process path arguments")); \ + return false; \ + } \ + } + +static INLINE +bool rm_cmd_set_paths(RmCfg *const cfg, char **const paths) { + g_assert(cfg); + + const bool replay = cfg->replay; + const bool read_stdin0 = cfg->read_stdin0; + RmCmdSetPathVars v = { + .cfg = cfg, + .paths = paths, + .index = cfg->path_count, + .read_stdin = read_stdin0, + .null_separated = read_stdin0, + .all_paths_valid = true + }; + + cfg->path_count = 0; + + if(replay) { + PROCESS_PATHS(true); + } else { + PROCESS_PATHS(false); } - if(g_slist_length(cfg->paths) == 0 && all_paths_valid) { + if(cfg->path_count == 0 && v.all_paths_valid) { /* Still no path set? - use `pwd` */ - rm_cfg_add_path(session->cfg, is_prefd, cfg->iwd); + rm_cfg_prepend_path( + cfg, cfg->iwd, v.index, /* replay */ false, v.is_prefd + ); } /* Only return success if everything is fine. */ - return all_paths_valid; + return v.all_paths_valid; } static bool rm_cmd_set_outputs(RmSession *session, GError **error) { @@ -1463,7 +1540,7 @@ bool rm_cmd_parse_args(int argc, char **argv, RmSession *session) { goto cleanup; } - if(!rm_cmd_set_paths(session, paths)) { + if(!rm_cmd_set_paths(cfg, paths)) { error = g_error_new(RM_ERROR_QUARK, 0, _("Not all given paths are valid. Aborting")); goto cleanup; } diff --git a/lib/formats/_equal.c b/lib/formats/_equal.c index b67f2663..a0661268 100644 --- a/lib/formats/_equal.c +++ b/lib/formats/_equal.c @@ -26,6 +26,7 @@ #include "../formats.h" #include "../utilities.h" #include "../preprocess.h" +#include "../path.h" #include #include diff --git a/lib/formats/progressbar.c b/lib/formats/progressbar.c index 57e9a1ae..16d2dc3c 100644 --- a/lib/formats/progressbar.c +++ b/lib/formats/progressbar.c @@ -132,7 +132,7 @@ static char *rm_fmt_progress_get_cached_eta( gint64 now = g_get_real_time(); if(self->last_eta[0] != 0) { - if(ABS(now - self->last_eta_update) <= 500 * 1000) { + if(ABS(now - self->last_eta_update) <= 500L * 1000) { return self->last_eta; } } diff --git a/lib/hash-utility.c b/lib/hash-utility.c index 68395b15..f79b9cd3 100644 --- a/lib/hash-utility.c +++ b/lib/hash-utility.c @@ -119,7 +119,7 @@ int rm_hasher_main(int argc, const char **argv) { /* Digest type */ tag.digest_type = RM_DEFAULT_DIGEST; gint threads = 8; - gint64 buffer_mbytes = 256; + guint64 buffer_mbytes = 256; guint64 increment = 4096; ////////////// Option Parsing /////////////// @@ -213,7 +213,7 @@ int rm_hasher_main(int argc, const char **argv) { threads, FALSE, increment, - 1024 * 1024 * buffer_mbytes, + 1024L * 1024 * buffer_mbytes, (RmHasherCallback)rm_hasher_callback, &tag); diff --git a/lib/md-scheduler.c b/lib/md-scheduler.c index 5cb44bf1..d6ec4bb8 100644 --- a/lib/md-scheduler.c +++ b/lib/md-scheduler.c @@ -30,9 +30,9 @@ * debug messages by continually recycling back to the joiner. */ #if _RM_MDS_DEBUG -#define MDS_EMPTYQUEUE_SLEEP_US (60 * 1000 * 1000) /* 60 seconds */ +#define MDS_EMPTYQUEUE_SLEEP_US (60L * 1000 * 1000) /* 60 seconds */ #else -#define MDS_EMPTYQUEUE_SLEEP_US (50 * 1000) /* 0.05 second */ +#define MDS_EMPTYQUEUE_SLEEP_US (50L * 1000) /* 0.05 second */ #endif /////////////////////////////////////// diff --git a/lib/path-funcs.h b/lib/path-funcs.h new file mode 100644 index 00000000..1f46ac0b --- /dev/null +++ b/lib/path-funcs.h @@ -0,0 +1,146 @@ +/** +* This file is part of rmlint. +* +* rmlint is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* rmlint is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rmlint. If not, see . +* +* Authors: +* +* - Christopher Pahl 2010-2017 (https://github.com/sahib) +* - Daniel T. 2014-2017 (https://github.com/SeeSpotRun) +* - Michael Witten 2018-2018 +* +* Hosted on http://github.com/sahib/rmlint +**/ + +#ifndef RM_PATH_FUNCS_H +#define RM_PATH_FUNCS_H + +#include // errno +#include // strerror +#include // bool, true, false +#include // free, realpath +#include // access, faccessat, R_OK +#include // struct stat, stat, S_ISREG +#include // g_assert, g_str_has_suffix, GSList, + // g_slist_prepend, GDestroyNotify +#if HAVE_FACCESSAT + #include // AT_FDCWD, AT_EACCESS +#endif + +#include "path.h" // RmPath +#include "config.h" // _, rm_log_warning_line + +static INLINE +void rm_path_free(RmPath *const p) { + g_assert(p); + free(p->path); + g_slice_free(RmPath, p); +} + +static INLINE +bool rm_path_is_real( + const char *const path, + char **const real_path +) { + g_assert(path); + g_assert(real_path); + + if((*real_path = realpath(path, 0))) { + return true; + } + + rm_log_warning_line( + _("Can't get real path for directory or file \"%s\": %s"), + path, strerror(errno) + ); + + return false; +} + +#if HAVE_FACCESSAT + #define NOT_ACCESSIBLE(path) faccessat(AT_FDCWD, path, R_OK, AT_EACCESS) +#else + #define NOT_ACCESSIBLE(path) access(path, R_OK) +#endif + +static INLINE +bool rm_path_is_accessible(const char *const path) { + g_assert(path); + if(NOT_ACCESSIBLE(path)) { + rm_log_warning_line( + _("Can't open directory or file \"%s\": %s"), + path, strerror(errno) + ); + return false; + } + return true; +} + +#undef NOT_ACCESSIBLE + +static INLINE +bool rm_path_is_valid( + const char *const path, + char **const real_path +) { + g_assert(path); + g_assert(real_path); + + if(rm_path_is_real(path, real_path)) { + return rm_path_is_accessible(*real_path); + } + + rm_log_warning_line(_("Invalid path \"%s\""), path); + return false; +} + +static INLINE +bool rm_path_is_file(const char *const path) { + g_assert(path); + struct stat s; + if(stat(path, &s)) { + rm_log_warning_line( + _("Could not get metadata for path \"%s\": %s"), + path, strerror(errno) + ); + return false; + } + return S_ISREG(s.st_mode); +} + +static INLINE +bool rm_path_is_json(const char *const path) { + g_assert(path); + return rm_path_is_file(path) && g_str_has_suffix(path, ".json"); +} + +static INLINE +void rm_path_prepend( + GSList **const list, + char *const path, + const unsigned int index, + const bool preferred +) { + g_assert(path); + + RmPath *p = g_slice_new(RmPath); + p->path = path; + p->index = index; + p->is_prefd = preferred; + p->single_volume = (path[0] == '/') && (path[1] == '/'); + + *list = g_slist_prepend(*list, p); +} + +#endif /* end of include guard */ diff --git a/lib/path.h b/lib/path.h new file mode 100644 index 00000000..b1a929c5 --- /dev/null +++ b/lib/path.h @@ -0,0 +1,38 @@ +/** +* This file is part of rmlint. +* +* rmlint is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* rmlint is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rmlint. If not, see . +* +* Authors: +* +* - Christopher Pahl 2010-2017 (https://github.com/sahib) +* - Daniel T. 2014-2017 (https://github.com/SeeSpotRun) +* - Michael Witten 2018-2018 +* +* Hosted on http://github.com/sahib/rmlint +**/ + +#ifndef RM_PATH_H +#define RM_PATH_H + +#include // bool + +typedef struct RmPath { + char *path; // result of `realpath()' of + unsigned int index; // command line order, followed by stdin order + bool is_prefd; // whether path was tagged as preferred path + bool single_volume; // treat this directory as one file system +} RmPath; + +#endif /* end of include guard */ diff --git a/lib/replay.c b/lib/replay.c index fad16294..23b7e67e 100644 --- a/lib/replay.c +++ b/lib/replay.c @@ -31,6 +31,7 @@ #include "preprocess.h" #include "session.h" #include "shredder.h" +#include "path.h" /* External libraries */ #include @@ -314,7 +315,7 @@ static bool rm_parrot_check_path(RmParrot *polly, RmFile *file, const char *file highest_match = path_len; file->is_prefd = rmpath->is_prefd || polly->is_prefd; - file->path_index = rmpath->idx; + file->path_index = rmpath->index; } } } diff --git a/lib/session.c b/lib/session.c index 3ccaa33e..9d8a1613 100644 --- a/lib/session.c +++ b/lib/session.c @@ -28,10 +28,12 @@ #include #include "config.h" +#include "cfg-funcs.h" #include "formats.h" #include "preprocess.h" #include "session.h" #include "traverse.h" +#include "path.h" #if HAVE_BTRFS_H #include @@ -230,7 +232,7 @@ int rm_session_dedupe_main(RmCfg *cfg) { /* clang-format on */ /* a poorly-documented limit for dedupe ioctl's */ - static const gint64 max_dedupe_chunk = 16 * 1024 * 1024; + static const gint64 max_dedupe_chunk = 16L * 1024 * 1024; /* how fine a resolution to use once difference detected; * use btrfs default node size (16k): */ diff --git a/lib/shredder.c b/lib/shredder.c index 0371f4ff..73840d3d 100644 --- a/lib/shredder.c +++ b/lib/shredder.c @@ -275,14 +275,14 @@ #define SHRED_PAGE_SIZE (sysconf(_SC_PAGESIZE)) #define SHRED_MAX_READ_FACTOR \ - ((256 * 1024 * 1024) / SHRED_BALANCED_PAGES / SHRED_PAGE_SIZE) + ((256L * 1024 * 1024) / SHRED_BALANCED_PAGES / SHRED_PAGE_SIZE) /* Maximum increment size for paranoid digests. This is smaller than for other * digest types due to memory management issues. * 16MB should be big enough buffer size to make seek time fairly insignificant * relative to sequential read time, eg 16MB read at typical 100 MB/s read * rate = 160ms read vs typical seek time 10ms*/ -#define SHRED_PARANOID_BYTES (16 * 1024 * 1024) +#define SHRED_PARANOID_BYTES (16L * 1024 * 1024) /* When paranoid hashing, if a file increments is larger * than SHRED_PREMATCH_THRESHOLD, we take a guess at the likely @@ -296,7 +296,7 @@ #define SHRED_AVERAGE_MEM_PER_FILE (100) /* Maximum number of bytes before worth_waiting becomes false */ -#define SHRED_TOO_MANY_BYTES_TO_WAIT (64 * 1024 * 1024) +#define SHRED_TOO_MANY_BYTES_TO_WAIT (64L * 1024 * 1024) /////////////////////////////////////////////////////////////////////// // INTERNAL STRUCTURES, WITH THEIR INITIALISERS AND DESTROYERS // @@ -1742,7 +1742,7 @@ void rm_shred_run(RmSession *session) { /* estimate mem used for RmFiles and allocate any leftovers to read buffer and/or * paranoid mem */ RmOff mem_used = SHRED_AVERAGE_MEM_PER_FILE * session->shred_files_remaining; - RmOff read_buffer_mem = MAX(1024 * 1024, (gint64)cfg->total_mem - (gint64)mem_used); + RmOff read_buffer_mem = MAX(1024L * 1024, cfg->total_mem - mem_used); if(cfg->checksum_type == RM_DIGEST_PARANOID) { /* allocate any spare mem for paranoid hashing */ diff --git a/lib/traverse.c b/lib/traverse.c index e8c6aef7..02c8736e 100644 --- a/lib/traverse.c +++ b/lib/traverse.c @@ -38,6 +38,7 @@ #include "preprocess.h" #include "utilities.h" #include "xattr.h" +#include "path.h" #include "fts/fts.h" @@ -238,7 +239,7 @@ static bool rm_traverse_is_hidden(RmCfg *cfg, const char *basename, char *hierar trav_session, (RmStat *)stat_buf, p->fts_path, is_prefd, path_index, lint_type, \ is_symlink, \ rm_traverse_is_hidden(cfg, p->fts_name, is_hidden, p->fts_level + 1), \ - rmpath->treat_as_single_vol, p->fts_level); + rmpath->single_volume, p->fts_level); #if RM_PLATFORM_32 && HAVE_STAT64 @@ -285,12 +286,12 @@ static void rm_traverse_directory(RmTravBuffer *buffer, RmTravSession *trav_sess RmPath *rmpath = buffer->rmpath; char is_prefd = rmpath->is_prefd; - RmOff path_index = rmpath->idx; + RmOff path_index = rmpath->index; /* Initialize ftsp */ int fts_flags = FTS_PHYSICAL | FTS_COMFOLLOW | FTS_NOCHDIR; - if(rmpath->treat_as_single_vol) { + if(rmpath->single_volume) { rm_log_debug_line("Treating files under %s as a single volume", rmpath->path); } @@ -404,7 +405,7 @@ static void rm_traverse_directory(RmTravBuffer *buffer, RmTravSession *trav_sess path_index, RM_LINT_TYPE_UNKNOWN, false, rm_traverse_is_hidden(cfg, p->fts_name, is_hidden, p->fts_level + 1), - rmpath->treat_as_single_vol, p->fts_level); + rmpath->single_volume, p->fts_level); rm_log_warning_line(_("Added big file %s"), p->fts_path); } else { rm_log_warning_line(_("cannot stat file %s (skipping)"), p->fts_path); @@ -521,7 +522,7 @@ void rm_traverse_tree(RmSession *session) { } rm_traverse_file(trav_session, &buffer->stat_buf, rmpath->path, - rmpath->is_prefd, rmpath->idx, RM_LINT_TYPE_UNKNOWN, false, + rmpath->is_prefd, rmpath->index, RM_LINT_TYPE_UNKNOWN, false, is_hidden, FALSE, 0); rm_trav_buffer_free(buffer); @@ -529,7 +530,7 @@ void rm_traverse_tree(RmSession *session) { /* It's a directory, traverse it. */ buffer->disk = rm_mds_device_get(mds, rmpath->path, (cfg->fake_pathindex_as_disk) - ? rmpath->idx + 1 + ? rmpath->index + 1 : buffer->stat_buf.st_dev); rm_mds_device_ref(buffer->disk, 1); rm_mds_push_task(buffer->disk, buffer->stat_buf.st_dev, 0, rmpath->path, diff --git a/lib/treemerge.c b/lib/treemerge.c index d7818a82..282a3462 100644 --- a/lib/treemerge.c +++ b/lib/treemerge.c @@ -82,6 +82,7 @@ #include "preprocess.h" #include "shredder.h" #include "treemerge.h" +#include "path.h" #include "fts/fts.h" @@ -188,7 +189,7 @@ static bool rm_tm_count_files(RmTrie *count_tree, const RmCfg *const cfg) { const char **const path_vec = malloc(sizeof(*path_vec) * (path_count + 1)); if(!path_vec) { - rm_log_error(_("Failed to allocate memory. Out of memory?")); + rm_log_perror(_("Failed to allocate memory")); return false; } diff --git a/lib/utilities.c b/lib/utilities.c index e768fa41..f438d2e1 100644 --- a/lib/utilities.c +++ b/lib/utilities.c @@ -374,9 +374,9 @@ char *rm_util_get_groupname(void) { void rm_util_size_to_human_readable(RmOff num, char *in, gsize len) { if(num < 512) { snprintf(in, len, "%" LLU " B", num); - } else if(num < 512 * 1024) { + } else if(num < 512L * 1024) { snprintf(in, len, "%.2f KB", num / 1024.0); - } else if(num < 512 * 1024 * 1024) { + } else if(num < 512L * 1024 * 1024) { snprintf(in, len, "%.2f MB", num / (1024.0 * 1024.0)); } else { snprintf(in, len, "%.2f GB", num / (1024.0 * 1024.0 * 1024.0)); @@ -1342,7 +1342,7 @@ bool rm_iso8601_format(time_t stamp, char *buf, gsize buf_size) { return false; } -#define SECONDS_PER_DAY (24 * 60 * 60) +#define SECONDS_PER_DAY (24L * 60 * 60) #define SECONDS_PER_HOUR (60 * 60) #define SECONDS_PER_MINUTE (60) diff --git a/po/de.po b/po/de.po index 60d40491..8f065b73 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: rmlint 2.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-04 18:46+0000\n" +"POT-Creation-Date: 2019-01-21 21:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -343,12 +343,12 @@ msgstr "Unbekanntes fts_info flag %d für Datei %s" msgid "'%s': fts_read failed on %s" msgstr "'%s': fts_read schlug fehl bei Pfad %s" -#: lib/cfg.c lib/hash-utility.c +#: lib/hash-utility.c lib/path-funcs.h #, c-format msgid "Can't open directory or file \"%s\": %s" msgstr "Kann Verzeichnis oder Datei \"%s\" nicht öffnen: %s" -#: lib/cfg.c +#: lib/path-funcs.h #, fuzzy, c-format msgid "Can't get real path for directory or file \"%s\": %s" msgstr "Kann Verzeichnis oder Datei \"%s\" nicht öffnen: %s" @@ -535,7 +535,7 @@ msgid "This does not look like a number" msgstr "Das schaut nicht wie eine Zahl aus" #: lib/cmdline.c -msgid "Negativ sizes are no good idea" +msgid "A size must be non-negative" msgstr "Negative Größen sind keine gute Idee" #: lib/cmdline.c @@ -1017,9 +1017,9 @@ msgstr "-K und -m sollten nicht gleichzeitig genutzt werden (siehe auch: https:/ msgid "Failed to complete setup for merging directories" msgstr "Schlug beim Setup des Verzeichnismergers fehl" -#: lib/treemerge.c -msgid "Failed to allocate memory. Out of memory?" -msgstr "Konnte kein Speicher allokieren. Kein Speicher mehr?" +#: lib/treemerge.c lib/cmdline.c +msgid "Failed to allocate memory" +msgstr "Konnte kein Speicher allokieren" #: lib/cmdline.c msgid "--replay (-Y) is incompatible with --dedupe or --is-reflink" @@ -1030,6 +1030,29 @@ msgstr "--replay (-Y) ist nicht kompatibel mit --dedupe oder --is-reflink" msgid "No stamp file at `%s`, will create one after this run." msgstr "Keine stamp Datei hier: `%s`. Es wird eine nach diesem Lauf erstellt." +#: lib/cmdline.c +#, c-format +msgid "Failed to include this replay file: %s" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Invalid path \"%s\"" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Could not get metadata for path \"%s\": %s" +msgstr "" + +#: lib/cmdline.c +msgid "Failed to read stdin" +msgstr "" + +#: lib/cmdline.c +msgid "Could not process path arguments" +msgstr "" + #~ msgid "%s%15" #~ msgstr "%s%15" diff --git a/po/es.po b/po/es.po index 7b6dd5c3..fd81c42d 100644 --- a/po/es.po +++ b/po/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: rmlint 2.4.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-04 18:46+0000\n" +"POT-Creation-Date: 2019-01-21 21:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -339,12 +339,12 @@ msgstr "Bandera fts_info %d desconocida para archivo %s" msgid "'%s': fts_read failed on %s" msgstr "'%s': fts_read falló en %s" -#: lib/cfg.c lib/hash-utility.c +#: lib/hash-utility.c lib/path-funcs.h #, c-format msgid "Can't open directory or file \"%s\": %s" msgstr "No se puede abrir el directorio o archivo \"%s\": %s" -#: lib/cfg.c +#: lib/path-funcs.h #, fuzzy, c-format msgid "Can't get real path for directory or file \"%s\": %s" msgstr "No se puede abrir el directorio o archivo \"%s\": %s" @@ -525,7 +525,7 @@ msgid "This does not look like a number" msgstr "Estto no parece un número" #: lib/cmdline.c -msgid "Negativ sizes are no good idea" +msgid "A size must be non-negative" msgstr "Tamaños negativos no son una buena idea" #: lib/cmdline.c @@ -992,8 +992,8 @@ msgstr "" msgid "Failed to complete setup for merging directories" msgstr "" -#: lib/treemerge.c -msgid "Failed to allocate memory. Out of memory?" +#: lib/treemerge.c lib/cmdline.c +msgid "Failed to allocate memory" msgstr "" #: lib/cmdline.c @@ -1005,6 +1005,29 @@ msgstr "" msgid "No stamp file at `%s`, will create one after this run." msgstr "" +#: lib/cmdline.c +#, c-format +msgid "Failed to include this replay file: %s" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Invalid path \"%s\"" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Could not get metadata for path \"%s\": %s" +msgstr "" + +#: lib/cmdline.c +msgid "Failed to read stdin" +msgstr "" + +#: lib/cmdline.c +msgid "Could not process path arguments" +msgstr "" + #~ msgid "caching is not supported due to missing json-glib library." #~ msgstr "" #~ "el cacheo no es soportado debido a la librería inexistente json-glib" diff --git a/po/fr.po b/po/fr.po index 229eee5c..ea5b2db4 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: rmlint 2.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-04 18:46+0000\n" +"POT-Creation-Date: 2019-01-21 21:40+0000\n" "PO-Revision-Date: 2014-12-02 13:37+0100\n" "Last-Translator: F. \n" "Language-Team: none\n" @@ -337,12 +337,12 @@ msgstr "Drapeau fts_info %d inconnu pour le fichier %s" msgid "'%s': fts_read failed on %s" msgstr "'%s': échec de fts_read pour %s" -#: lib/cfg.c lib/hash-utility.c +#: lib/hash-utility.c lib/path-funcs.h #, fuzzy, c-format msgid "Can't open directory or file \"%s\": %s" msgstr "Impossible d'ouvrir le répertoire ou le fichier \"%s\": %s\n" -#: lib/cfg.c +#: lib/path-funcs.h #, fuzzy, c-format msgid "Can't get real path for directory or file \"%s\": %s" msgstr "Impossible d'ouvrir le répertoire ou le fichier \"%s\": %s\n" @@ -513,7 +513,7 @@ msgid "This does not look like a number" msgstr "Cela ne semble pas correspondre à un chiffre" #: lib/cmdline.c -msgid "Negativ sizes are no good idea" +msgid "A size must be non-negative" msgstr "Une taille négative n'est pas une bonne idée" #: lib/cmdline.c @@ -988,8 +988,8 @@ msgstr "" msgid "Failed to complete setup for merging directories" msgstr "" -#: lib/treemerge.c -msgid "Failed to allocate memory. Out of memory?" +#: lib/treemerge.c lib/cmdline.c +msgid "Failed to allocate memory" msgstr "" #: lib/cmdline.c @@ -1001,6 +1001,29 @@ msgstr "" msgid "No stamp file at `%s`, will create one after this run." msgstr "" +#: lib/cmdline.c +#, c-format +msgid "Failed to include this replay file: %s" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Invalid path \"%s\"" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Could not get metadata for path \"%s\": %s" +msgstr "" + +#: lib/cmdline.c +msgid "Failed to read stdin" +msgstr "" + +#: lib/cmdline.c +msgid "Could not process path arguments" +msgstr "" + #~ msgid "caching is not supported due to missing json-glib library." #~ msgstr "Cache non supporté, librairie json-glib manquante." diff --git a/po/rmlint.pot b/po/rmlint.pot index 6523c2d2..74e4cbff 100644 --- a/po/rmlint.pot +++ b/po/rmlint.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: rmlint 2.8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-29 23:47+0100\n" +"POT-Creation-Date: 2019-01-21 21:40+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -334,12 +334,12 @@ msgstr "" msgid "'%s': fts_read failed on %s" msgstr "" -#: lib/cfg.c lib/hash-utility.c +#: lib/hash-utility.c lib/path-funcs.h #, c-format msgid "Can't open directory or file \"%s\": %s" msgstr "" -#: lib/cfg.c +#: lib/path-funcs.h #, c-format msgid "Can't get real path for directory or file \"%s\": %s" msgstr "" @@ -503,7 +503,7 @@ msgid "This does not look like a number" msgstr "" #: lib/cmdline.c -msgid "Negativ sizes are no good idea" +msgid "A size must be non-negative" msgstr "" #: lib/cmdline.c @@ -937,8 +937,8 @@ msgstr "" msgid "Failed to complete setup for merging directories" msgstr "" -#: lib/treemerge.c -msgid "Failed to allocate memory. Out of memory?" +#: lib/treemerge.c lib/cmdline.c +msgid "Failed to allocate memory" msgstr "" #: lib/cmdline.c @@ -949,3 +949,26 @@ msgstr "" #, c-format msgid "No stamp file at `%s`, will create one after this run." msgstr "" + +#: lib/cmdline.c +#, c-format +msgid "Failed to include this replay file: %s" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Invalid path \"%s\"" +msgstr "" + +#: lib/path-funcs.h +#, c-format +msgid "Could not get metadata for path \"%s\": %s" +msgstr "" + +#: lib/cmdline.c +msgid "Failed to read stdin" +msgstr "" + +#: lib/cmdline.c +msgid "Could not process path arguments" +msgstr ""