diff --git a/HISTORY b/HISTORY index 5266e09b..121a052b 100644 --- a/HISTORY +++ b/HISTORY @@ -4,6 +4,7 @@ SnapRAID HISTORY 1.3 2011/5 ========== * Fixed the restore of directory with unicode chars in Windows. +* Fixed support of file names starting or ending with a space. 1.2 2011/5 ========== diff --git a/scan.c b/scan.c index ba441c7b..521a5afb 100644 --- a/scan.c +++ b/scan.c @@ -225,7 +225,7 @@ static void scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, s continue; /* check for not supported file names, limitation derived from the content file format */ - if (name[0] == 0 || isspace(name[0]) || isspace(name[strlen(name)-1])) { + if (name[0] == 0 || strchr(name, '\n') != 0 || name[strlen(name)-1] == '\r') { fprintf(stderr, "Unsupported name '%s' in file '%s'.\n", name, path_next); exit(EXIT_FAILURE); } diff --git a/snapraid.1 b/snapraid.1 index 4a89964a..68b4e933 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -737,6 +737,19 @@ http://kernel.org/pub/linux/kernel/people/hpa/raid6.pdf When a file block is shorter than the default block size, for example because it\(cqs the last block of a file, it\(cqs assumed as filled with 0 at the end. +.SH ENCODING +SnapRAID in Unix ignores any encoding. It simply read and stores the +file names with the same encoding used by the filesystem. +.PP +In Windows all the names read from the filesystem are converted and +processed in the UTF\(hy8 format. +.PP +To have the file names printed correctly you have to set the Windows +console in the UTF\(hy8 mode, with the command \(a"chmod 65001\(a", and use +a TrueType font like \(a"Lucida Console\(a" for the console font. +Note that it has effect only on the printed file names, if you +redirect the console output to a file, the resulting file is always +in the UTF\(hy8 format. .SH COPYRIGHT This file is Copyright (C) 2011 Andrea Mazzoleni .SH SEE ALSO diff --git a/snapraid.d b/snapraid.d index 3a843378..1d36c29a 100644 --- a/snapraid.d +++ b/snapraid.d @@ -488,6 +488,20 @@ Parity because it's the last block of a file, it's assumed as filled with 0 at the end. +Encoding + SnapRAID in Unix ignores any encoding. It simply read and stores the + file names with the same encoding used by the filesystem. + + In Windows all the names read from the filesystem are converted and + processed in the UTF-8 format. + + To have the file names printed correctly you have to set the Windows + console in the UTF-8 mode, with the command "chmod 65001", and use + a TrueType font like "Lucida Console" for the console font. + Note that it has effect only on the printed file names, if you + redirect the console output to a file, the resulting file is always + in the UTF-8 format. + Copyright This file is Copyright (C) 2011 Andrea Mazzoleni diff --git a/snapraid.txt b/snapraid.txt index 91f875cc..179d8fb6 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -520,13 +520,30 @@ because it's the last block of a file, it's assumed as filled with 0 at the end. -11 COPYRIGHT +11 ENCODING +=========== + +SnapRAID in Unix ignores any encoding. It simply read and stores the +file names with the same encoding used by the filesystem. + +In Windows all the names read from the filesystem are converted and +processed in the UTF-8 format. + +To have the file names printed correctly you have to set the Windows +console in the UTF-8 mode, with the command "chmod 65001", and use +a TrueType font like "Lucida Console" for the console font. +Note that it has effect only on the printed file names, if you +redirect the console output to a file, the resulting file is always +in the UTF-8 format. + + +12 COPYRIGHT ============ This file is Copyright (C) 2011 Andrea Mazzoleni -12 SEE ALSO +13 SEE ALSO =========== rsync(1) diff --git a/state.c b/state.c index b4a498a6..e77bb77a 100644 --- a/state.c +++ b/state.c @@ -99,9 +99,12 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i /* start */ s = buffer; - s = strskip(s); - /* ignore commens and empty lines */ + /* skip initial spaces */ + while (*s && isspace(*s)) + ++s; + + /* ignore comments and empty lines */ if (*s == '#' || *s == 0) continue; @@ -261,9 +264,12 @@ void state_read(struct snapraid_state* state) /* start */ s = buffer; - s = strskip(s); - /* ignore commens and empty lines */ + /* skip initial spaces */ + while (*s && isspace(*s)) + ++s; + + /* ignore comments and empty lines */ if (*s == '#' || *s == 0) continue; diff --git a/util.c b/util.c index bcb579a7..d81271aa 100644 --- a/util.c +++ b/util.c @@ -58,9 +58,10 @@ int strgets(char* s, unsigned size, FILE* f) return 0; } - /* remove ending spaces */ - while (i != s && isspace(i[-1])) + /* remove ending carrige return to support the Windows CR+LF format */ + if (i != s && i[-1] == '\r') --i; + *i = 0; return 1; diff --git a/util.h b/util.h index a725f639..fa28e19a 100644 --- a/util.h +++ b/util.h @@ -22,26 +22,16 @@ /* string */ /** - * Marks the end of the current token, and move to the next one. + * Marks the end of the current token, and skip one and only one separator if present. */ static inline char* strtoken(char* s) { while (*s && *s != ' ') ++s; - if (*s) - *s++ = 0; - while (*s == ' ') - ++s; - return s; -} - -/** - * Move to the next token skipping any separator. - */ -static inline char* strskip(char* s) -{ - while (*s == ' ') + if (*s) { + *s = 0; ++s; + } return s; }