From e0acbda4bd686214d7981e5805aa3e2b107a0d10 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 1 Mar 2013 00:12:57 +0100 Subject: [PATCH] Opens filtered out files in read-only mode. --- TODO | 2 -- check.c | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 7096998c..84a56933 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,6 @@ This 'init' will work also without a content file, and parity files. Instead 'sync' will require all of them. This will also help when running with the parity filesystem unmounted. -* Filtered out files should be opened in read-only mode. - * Adds a log option, to save log files with the date in the name. This could help to keep track of what happens during automated operations. We must keep the log to stdout/err, and only save a copy to the log file. diff --git a/check.c b/check.c index 3a820085..f4ae4039 100644 --- a/check.c +++ b/check.c @@ -602,7 +602,8 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, } } - if (fix) { + /* if fixing, and the file is not excluded, we must open for writing */ + if (fix && !file_flag_has(block_file_get(block), FILE_IS_EXCLUDED)) { /* if fixing, create the file, open for writing and resize if required */ ret = handle_create(&handle[j], block_file_get(block)); if (ret == -1) { @@ -627,7 +628,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, ++recovered_error; } } else { - /* if checking or hashing, open the file for reading */ + /* if checking or hashing, open the file only for reading */ ret = handle_open(&handle[j], block_file_get(block)); if (ret == -1) { /* save the failed block for the check/fix */ @@ -914,6 +915,17 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, continue; } + /* if the file is excluded, we have nothing to fix */ + /* note that this check is required, because if the file is excluded */ + /* it's also possible to have it not opened, */ + /* and have the handle[j].file pointing to NULL. */ + /* A typical case is if the file is missing, */ + /* and the read-only open failed before. */ + if (file_flag_has(block_file_get(block), FILE_IS_EXCLUDED)) { + /* nothing to do */ + continue; + } + /* if it isn't the last block in the file */ if (!block_is_last(block)) { /* nothing to do */