From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Date: Mon, 28 Apr 2008 08:48:13 +0000 From: eekee57 Message-ID: <84378423-1ad3-42a8-8948-2e3291a79dd0@j22g2000hsf.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [9fans] ftpfs ahould not expose "." and ".." directories Topicbox-Message-UUID: 9a1cfbb2-ead3-11e9-9d60-3106f5b1d025 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