9fans archive / 2008 / 04 / 342 / prev next
From: Pietro Gagliardi <pietro10@mac.com>
Subject: Re: [9fans] ftpfs ahould not expose "." and ".." directories
Date: Mon, 28 Apr 2008 06:19:32 -0400
You do realize using strncmp means that a filename like .abc
or ..whatever will also get hidden? There is no notion of a hidden
file in Plan 9, nor is there an option to ls to show them. It's only
necessary to hide . and .., not whatever the other system feels is a
hidden file.
Also note that FTP servers using FAT don't use . to hide files -
there's a bit in the attribute field. This will mean trouble for one
with long file names, where the placement of periods is much more
lenient.
664a665,666
> if(!strcmp(".", field[7]) || !strcmp("..", field[7]))
> return nil;
675a678,679
> if(!strcmp(".", field[8], 2) || !strcmp("..", field[8]))
> return nil;
686a691,692
> if(!strcmp(".", field[9]) || !strcmp("..", field[9]))
> return nil;
697a704,705
> if(!strcmp(".", field[3]) || !strcmp("..", field[3]))
> return nil;
712a721,722
> if(!strcmp(".", field[0]) || !strcmp("..", field[0]))
> return nil;
On Apr 28, 2008, at 4:48 AM, eekee57 wrote:
> Hi all. I had a problem trying to use dircp with ftpfs the other day,
> and made a little patch to ftpfs to fix it.
>
> The Problem: Many operating systems expose the psuedo-directories "."
> and ".." in their directory structure, and understandably many FTP
> servers running on those operating systems pass the pseudo-directories
> on to their clients. Plan 9 does does not expose those psuedo-
> directories, so Plan 9's tar program does not treat them specially.
> ftpfs does not hide the pseudo-directories, so Plan 9 tar (and thus
> the dircp script too) will fail on encountering them, getting into a
> loop until the sequence of directory/../directory/../directory/../
> etc. just gets too long. Note that tar may fail to pack all files in
> the tree before failing.
>
> My Fix: I have added a little code to ftpfs to hide the "." and ".."
> directories when the server operating system is detected as UNIX,
> Windows-NT, or Plan 9. I included the Plan 9 case because these 3
> operating systems are lumped together in the code, and the heuristics
> to tell them apart by detail may be fooled by some server which
> happens to list files in a similar manner.
>
> My code consists of 5 near-identical if statements in the function
> that parses each line returned from an ftp LIST or NLST command:
>
> 664a665,666
>> if(!strncmp(".", field[7], 2) || !strncmp("..", field[7], 3))
>> return nil;
> 675a678,679
>> if(!strncmp(".", field[8], 2) || !strncmp("..", field[8], 3))
>> return nil;
> 686a691,692
>> if(!strncmp(".", field[9], 2) || !strncmp("..", field[9], 3))
>> return nil;
> 697a704,705
>> if(!strncmp(".", field[3], 2) || !strncmp("..", field[3], 3))
>> return nil;
> 712a721,722
>> if(!strncmp(".", field[0], 2) || !strncmp("..", field[0], 3))
>> return nil;
>
> return nil results in ftpfs ignoring that line of the listing
> entirely. strncmp() may not be the best function as it is supposed to
> compare lexicographically. I'm not sure whether a "lexicographic"
> comparison is appropriate, but I think Plan 9 strncmp is currently a
> simple byte-by-byte comparison.
>
> Patched /sys/src/cmd/ip/ftpfs/proto.c file:
> http://eekee.org.uk/plan9/ftpfs..patch/proto.c
>
> Also FYC are an ed script and a context diff:
> http://eekee.org.uk/plan9/ftpfs..patch/diff.ed
> http://eekee.org.uk/plan9/ftpfs..patch/diff.context
>