From d5c0a8c2f32ac96d4151bc94aa42d0bf06fdf4a9 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 18 Dec 2015 19:41:49 +0100 Subject: [PATCH] Support the case of an empty symlink There is the report of a such condition in Windows. --- HISTORY | 1 + cmdline/scan.c | 2 ++ cmdline/state.c | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index 07ababf7..23302423 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,7 @@ SnapRAID HISTORY 9.2 2015/12 =========== + * Allows symlinks pointing to an empty target. * Adds UUID support to Btrfs filesystems. It's available only if the libblkid library is available on the system. diff --git a/cmdline/scan.c b/cmdline/scan.c index f428f842..43da04de 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -1325,6 +1325,8 @@ static int scan_dir(struct snapraid_scan* scan, int level, int is_diff, const ch exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } + if (ret == 0) + log_fatal("WARNING! Empty symbolic link '%s'.\n", path_next); /* readlink doesn't put the final 0 */ subnew[ret] = 0; diff --git a/cmdline/state.c b/cmdline/state.c index 424d997f..cc8acad9 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -1738,6 +1738,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); + log_fatal("Internal inconsistency for null file!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2100,15 +2101,16 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } - ret = sgetbs(f, linkto, sizeof(linkto)); - if (ret < 0) { + if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); + log_fatal("Internal inconsistency for null symlink!\n"); os_abort(); /* LCOV_EXCL_STOP */ } - if (!*sub || !*linkto) { + ret = sgetbs(f, linkto, sizeof(linkto)); + if (ret < 0) { /* LCOV_EXCL_START */ decoding_error(path, f); os_abort(); @@ -2150,6 +2152,14 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + if (!*sub) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal("Internal inconsistency for null hardlink!\n"); + os_abort(); + /* LCOV_EXCL_STOP */ + } + ret = sgetbs(f, linkto, sizeof(linkto)); if (ret < 0) { /* LCOV_EXCL_START */ @@ -2158,9 +2168,10 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } - if (!*sub || !*linkto) { + if (!*linkto) { /* LCOV_EXCL_START */ decoding_error(path, f); + log_fatal("Internal inconsistency for empty hardlink '%s'!\n", sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2202,6 +2213,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); + log_fatal("Internal inconsistency for null dir!\n"); os_abort(); /* LCOV_EXCL_STOP */ }