mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Remove unnecessary prefix char in escaping
We can encode it at higher level.
This commit is contained in:
parent
256db0e595
commit
dd87022490
5 changed files with 14 additions and 22 deletions
|
|
@ -902,7 +902,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub,
|
|||
/* LCOV_EXCL_START */
|
||||
log_fatal("The file '%s%s' has unexpected zero size!\n", disk->dir, sub);
|
||||
log_fatal("It's possible that after a kernel crash this file was lost,\n");
|
||||
log_fatal("and you can use 'snapraid fix -f %s' to recover it.\n", esc_shell('/', sub, esc_buffer));
|
||||
log_fatal("and you can use 'snapraid fix -f /%s' to recover it.\n", esc_shell(sub, esc_buffer));
|
||||
if (!is_diff) {
|
||||
log_fatal("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command);
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
|
|||
|
|
@ -101,17 +101,17 @@ void test(int argc, char* argv[])
|
|||
for (i = 2; i < argc; ++i) {
|
||||
printf("argv[%d]\n", i);
|
||||
printf("\t#%s#\n", argv[i]);
|
||||
printf("\t#%s#\n", esc_shell(0, argv[i], buffer));
|
||||
printf("\t#%s#\n", esc_shell(argv[i], buffer));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
assert(strcmp(esc_shell(0, " ", buffer), "\" \"") == 0);
|
||||
assert(strcmp(esc_shell(0, " \" ", buffer), "\" \"\\\"\" \"") == 0);
|
||||
assert(strcmp(esc_shell(0, "&|()<>^", buffer), "^&^|^(^)^<^>^^") == 0);
|
||||
assert(strcmp(esc_shell(0, "&|()<>^ ", buffer), "\"&|()<>^ \"") == 0);
|
||||
assert(strcmp(esc_shell(" ", buffer), "\" \"") == 0);
|
||||
assert(strcmp(esc_shell(" \" ", buffer), "\" \"\\\"\" \"") == 0);
|
||||
assert(strcmp(esc_shell("&|()<>^", buffer), "^&^|^(^)^<^>^^") == 0);
|
||||
assert(strcmp(esc_shell("&|()<>^ ", buffer), "\"&|()<>^ \"") == 0);
|
||||
#else
|
||||
assert(strcmp(esc_shell(0, ",._+:@%%/-", buffer), ",._+:@%%/-") == 0);
|
||||
assert(strcmp(esc_shell(0, " ", buffer), "\\ ") == 0);
|
||||
assert(strcmp(esc_shell(",._+:@%%/-", buffer), ",._+:@%%/-") == 0);
|
||||
assert(strcmp(esc_shell(" ", buffer), "\\ ") == 0);
|
||||
#endif
|
||||
|
||||
printf("Everything OK\n");
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ bail:
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
const char* esc_shell(char prefix, const char* str, char* buffer)
|
||||
const char* esc_shell(const char* str, char* buffer)
|
||||
{
|
||||
char* begin = buffer;
|
||||
char* end = begin + ESC_MAX;
|
||||
|
|
@ -446,13 +446,6 @@ const char* esc_shell(char prefix, const char* str, char* buffer)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* add the prefix char, if any */
|
||||
if (prefix) {
|
||||
if (p == end)
|
||||
goto bail;
|
||||
*p++ = prefix;
|
||||
}
|
||||
|
||||
/* copy string with escaping */
|
||||
while (*str) {
|
||||
char c = *str;
|
||||
|
|
|
|||
|
|
@ -227,10 +227,9 @@ const char* esc_tag(const char* str, char* buffer);
|
|||
/**
|
||||
* Escape a string for the shell.
|
||||
*
|
||||
* \param prefix Char to prefix at the string.
|
||||
* \param buffer Preallocated buffer of ESC_MAX size.
|
||||
*/
|
||||
const char* esc_shell(char prefix, const char* str, char* buffer);
|
||||
const char* esc_shell(const char* str, char* buffer);
|
||||
|
||||
/**
|
||||
* Polish a string.
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno));
|
||||
log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n");
|
||||
log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path);
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', file->sub, esc_buffer));
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(file->sub, esc_buffer));
|
||||
++error;
|
||||
goto bail;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -239,7 +239,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc_tag(file->sub, esc_buffer), file_pos, strerror(errno));
|
||||
log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n");
|
||||
log_fatal("Ensure that file '%s' can be read.\n", handle[j].path);
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', file->sub, esc_buffer));
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(file->sub, esc_buffer));
|
||||
++error;
|
||||
goto bail;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -571,7 +571,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas
|
|||
log_tag("error:%u:%s:%s: Open error. %s\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), strerror(errno));
|
||||
log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n");
|
||||
log_fatal("Ensure that file '%s' can be accessed.\n", handle->path);
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', task->file->sub, esc_buffer));
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(task->file->sub, esc_buffer));
|
||||
task->state = TASK_STATE_ERROR;
|
||||
return;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -613,7 +613,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas
|
|||
log_tag("error:%u:%s:%s: Read error at position %u. %s\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), task->file_pos, strerror(errno));
|
||||
log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n");
|
||||
log_fatal("Ensure that file '%s' can be read.\n", handle->path);
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', task->file->sub, esc_buffer));
|
||||
log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(task->file->sub, esc_buffer));
|
||||
task->state = TASK_STATE_ERROR;
|
||||
return;
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue