Rename append-path-naive to append-relative-path, fix bugs to support Firefox FTP again

db4
Doug Coleman 2010-09-05 00:40:47 -05:00
parent 0ec1a89f54
commit 4b6946da45
2 changed files with 23 additions and 16 deletions

View File

@ -49,6 +49,17 @@ C: <ftp-disconnect> ftp-disconnect
[ but-last-slice [ "-" (send-response) ] with each ] [ but-last-slice [ "-" (send-response) ] with each ]
[ first " " (send-response) ] 2bi ; [ first " " (send-response) ] 2bi ;
: make-path-relative? ( path -- ? )
{
[ absolute-path? ]
[ drop server get serving-directory>> ]
} 1&& ;
: fixup-relative-path ( string -- string' )
dup make-path-relative? [
[ server get serving-directory>> ] dip append-relative-path
] when ;
: server-response ( string n -- ) : server-response ( string n -- )
2dup number>string swap ":" glue \ server-response DEBUG log-message 2dup number>string swap ":" glue \ server-response DEBUG log-message
<ftp-response> <ftp-response>
@ -120,9 +131,13 @@ ERROR: type-error type ;
: port>bytes ( port -- hi lo ) : port>bytes ( port -- hi lo )
[ -8 shift ] keep [ 8 bits ] bi@ ; [ -8 shift ] keep [ 8 bits ] bi@ ;
: display-directory ( -- string )
current-directory get server get serving-directory>> swap ?head drop
[ "/" ] when-empty ;
: handle-PWD ( obj -- ) : handle-PWD ( obj -- )
drop drop
current-directory get "\"" dup surround 257 server-response ; display-directory get "\"" dup surround 257 server-response ;
: handle-SYST ( obj -- ) : handle-SYST ( obj -- )
drop drop
@ -167,8 +182,9 @@ GENERIC: handle-passive-command ( stream obj -- )
M: ftp-list handle-passive-command ( stream obj -- ) M: ftp-list handle-passive-command ( stream obj -- )
drop drop
start-directory [ start-directory [
utf8 encode-output utf8 encode-output [
[ current-directory get directory. ] with-string-writer string-lines current-directory get directory.
] with-string-writer string-lines
harvest [ ftp-send ] each harvest [ ftp-send ] each
] with-output-stream finish-directory ; ] with-output-stream finish-directory ;
@ -225,6 +241,7 @@ M: ftp-disconnect handle-passive-command ( stream obj -- )
: handle-RETR ( obj -- ) : handle-RETR ( obj -- )
tokenized>> second tokenized>> second
fixup-relative-path
dup can-serve-file? [ dup can-serve-file? [
<ftp-get> fulfill-client <ftp-get> fulfill-client
] [ ] [
@ -261,6 +278,7 @@ M: ftp-disconnect handle-passive-command ( stream obj -- )
: handle-MDTM ( obj -- ) : handle-MDTM ( obj -- )
tokenized>> 1 swap ?nth [ tokenized>> 1 swap ?nth [
fixup-relative-path
dup file-info dup directory? [ dup file-info dup directory? [
drop not-a-plain-file drop not-a-plain-file
] [ ] [
@ -281,17 +299,6 @@ ERROR: no-directory-permissions ;
: directory-change-failed ( -- ) : directory-change-failed ( -- )
"Failed to change directory." 553 server-response ; "Failed to change directory." 553 server-response ;
: make-path-relative? ( path -- ? )
{
[ absolute-path? ]
[ drop server get serving-directory>> ]
} 1&& ;
: fixup-relative-path ( string -- string' )
dup make-path-relative? [
[ server get serving-directory>> ] dip append-path-naive
] when ;
: handle-CWD ( obj -- ) : handle-CWD ( obj -- )
tokenized>> 1 swap ?nth [ tokenized>> 1 swap ?nth [
fixup-relative-path fixup-relative-path

View File

@ -87,7 +87,7 @@ PRIVATE>
[ f ] [ f ]
} cond nip ; } cond nip ;
: append-path-naive ( path1 path2 -- path ) : append-relative-path ( path1 path2 -- path )
[ trim-tail-separators ] [ trim-tail-separators ]
[ trim-head-separators ] bi* "/" glue ; [ trim-head-separators ] bi* "/" glue ;
@ -105,7 +105,7 @@ PRIVATE>
{ [ over absolute-path? over first path-separator? and ] [ { [ over absolute-path? over first path-separator? and ] [
[ 2 head ] dip append [ 2 head ] dip append
] } ] }
[ append-path-naive ] [ append-relative-path ]
} cond ; } cond ;
: prepend-path ( path1 path2 -- path ) : prepend-path ( path1 path2 -- path )