diff options
author | Michal Novotny <michal@allpeers.com> | 2009-08-10 13:44:25 +0200 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2009-08-10 13:44:25 +0200 |
commit | fb45c08fac5219b26f278aa452bc26108a0c8f3f (patch) | |
tree | e8aa5a9bdbdeb0c8c0271012275c151693da6546 /daemon/ParseFTPList.c | |
parent | d59c121f60ec98f8241dcd611124510ceddaadfa (diff) | |
download | gvfs-fb45c08fac5219b26f278aa452bc26108a0c8f3f.tar.gz |
Bug 576229 – Doesn't handle files with leading space (upstream)
ParseFTPList can't handle regular unix ls -l listing of filenames
starting with spaces
upstream references:
http://bugzilla.mozilla.org/show_bug.cgi?id=484684
http://hg.mozilla.org/mozilla-central/rev/179c6f22d6f2
Diffstat (limited to 'daemon/ParseFTPList.c')
-rw-r--r-- | daemon/ParseFTPList.c | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/daemon/ParseFTPList.c b/daemon/ParseFTPList.c index 577840c7..9d4c1828 100644 --- a/daemon/ParseFTPList.c +++ b/daemon/ParseFTPList.c @@ -790,6 +790,12 @@ int ParseFTPList(const char *line, struct list_state *state, if (*tokens[2] != '<') /* not <DIR> or <JUNCTION> */ { + // try to handle correctly spaces at the beginning of the filename + // filesize (token[2]) must end at offset 38 + if (tokens[2] + toklen[2] - line == 38) { + result->fe_fname = &(line[39]); + result->fe_fnlen = p - result->fe_fname; + } result->fe_type = 'f'; pos = toklen[2]; while (pos > (sizeof(result->fe_size)-1)) @@ -797,29 +803,40 @@ int ParseFTPList(const char *line, struct list_state *state, memcpy( result->fe_size, tokens[2], pos ); result->fe_size[pos] = '\0'; } - else if ((tokens[2][1]) != 'D') /* not <DIR> */ - { - result->fe_type = '?'; /* unknown until junc for sure */ - if (result->fe_fnlen > 4) + else { + // try to handle correctly spaces at the beginning of the filename + // token[2] must begin at offset 24, the length is 5 or 10 + // token[3] must begin at offset 39 or higher + if (tokens[2] - line == 24 && (toklen[2] == 5 || toklen[2] == 10) && + tokens[3] - line >= 39) { + result->fe_fname = &(line[39]); + result->fe_fnlen = p - result->fe_fname; + } + + if ((tokens[2][1]) != 'D') /* not <DIR> */ { - p = result->fe_fname; - for (pos = result->fe_fnlen - 4; pos > 0; pos--) + result->fe_type = '?'; /* unknown until junc for sure */ + if (result->fe_fnlen > 4) { - if (p[0] == ' ' && p[3] == ' ' && p[2] == '>' && - (p[1] == '=' || p[1] == '-')) + p = result->fe_fname; + for (pos = result->fe_fnlen - 4; pos > 0; pos--) { - result->fe_type = 'l'; - result->fe_fnlen = p - result->fe_fname; - result->fe_lname = p + 4; - result->fe_lnlen = &(line[linelen]) - - result->fe_lname; - break; + if (p[0] == ' ' && p[3] == ' ' && p[2] == '>' && + (p[1] == '=' || p[1] == '-')) + { + result->fe_type = 'l'; + result->fe_fnlen = p - result->fe_fname; + result->fe_lname = p + 4; + result->fe_lnlen = &(line[linelen]) + - result->fe_lname; + break; + } + p++; } - p++; - } + } } } - + result->fe_time.tm_mon = atoi(tokens[0]+0); if (result->fe_time.tm_mon != 0) { @@ -987,6 +1004,8 @@ int ParseFTPList(const char *line, struct list_state *state, * "drwxr-xr-x 2 0 0 512 May 28 22:17 etc" */ + gboolean is_old_Hellsoft = FALSE; + if (numtoks >= 6) { /* there are two perm formats (Hellsoft/NetWare and *IX strmode(3)). @@ -1012,6 +1031,8 @@ int ParseFTPList(const char *line, struct list_state *state, { /* rest is FMA[S] or AFM[S] */ lstyle = 'U'; /* very likely one of the NetWare servers */ + if (toklen[0] == 10) + is_old_Hellsoft = TRUE; } } } @@ -1160,7 +1181,13 @@ int ParseFTPList(const char *line, struct list_state *state, } /* time/year */ - result->fe_fname = tokens[tokmarker+4]; + // there is exacly 1 space between filename and previous token in all + // outputs except old Hellsoft + if (!is_old_Hellsoft) + result->fe_fname = tokens[tokmarker+3] + toklen[tokmarker+3] + 1; + else + result->fe_fname = tokens[tokmarker+4]; + result->fe_fnlen = (&(line[linelen])) - (result->fe_fname); @@ -1171,7 +1198,7 @@ int ParseFTPList(const char *line, struct list_state *state, guint32 fe_size = atoi(result->fe_size); if (result->fe_fnlen > (fe_size + 4) && - g_strncmp(result->fe_fname + result->fe_fnlen - fe_size - 4 , " -> ", 4) == 0) + strncmp(result->fe_fname + result->fe_fnlen - fe_size - 4 , " -> ", 4) == 0) { result->fe_lname = result->fe_fname + (result->fe_fnlen - fe_size); result->fe_lnlen = (&(line[linelen])) - (result->fe_lname); |