Fixes support of file names starting or ending with a space.

This commit is contained in:
Andrea Mazzoleni 2011-05-24 21:03:30 +02:00
parent 58f191ef1f
commit 35f3c092ed
8 changed files with 65 additions and 23 deletions

View file

@ -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
==========

2
scan.c
View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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)

14
state.c
View file

@ -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;

5
util.c
View file

@ -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;

18
util.h
View file

@ -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;
}