[Patch] Fish upload problems.

buc buc at odusz.so-cdu.ru
Thu Nov 25 11:59:43 UTC 2004


   Midnight Commander has a FISH virtual filesystem (FIle transfer over
SHell). There is one old problem in MC implementation of it -- uploads
onto remote system.
   To do such an upload, MC should invoke on the remote side a command,
which reads appropriate number of bytes from stdin and store them in the
target file. Initially, `dd' command had been chosen for this purpose.
 


   The decision was such:
" ( dd bs=4096 count=<size/4096> ; dd bs=<size%4096> count=1 ) | ( cat
  >target_file ; cat >/dev/null ) "
   (Note: additional cat to /dev/null is needed to flush input on write
errors).
   But unfortunately, this variant appeared unreliable. The design of
`dd' does not assume full filling of input buffers on read (see, for
example, "conv=sync" description in `dd' manual). The design of `ssh' is
those that sometimes data can be written into pipe by portions of
different size. Therefore the part of data could remain not read by `dd' ...

   In the current version, the problem is solved as:
" dd bs=1 count=<size> | ..... "
i.e., `dd' reads input byte-by-byte. It is robast, but is very slow and
grabs a lot of cpu time on the remote system.
 


   The better decision is possible.
   There is `head' command. It has `-c <number>' option, which does what
we really need. The necessary amount of data is read from stdin reliably.
   Unfortunately, the remote system (any *NIX-like) may not have `head'
command, or have another implementation of it. But for such systems we
can still use `dd' .
                  The final decision is:
" ( head -c <size> -q - || dd bs=1 count=<size> ) | ( cat >target_file ;
cat >/dev/null ) "
   Either fast `head' is used, or `dd' as a fallback.
 


   If there is no `head' on the remote side, or `head' is too old (has no
`-c' option), then `dd' will be used. `-q' and `-' are used to cause
most non-GNU `head's to fail (by "incorrect" option). We can not trust
non-GNU implementations of `head' -- for example, AIX has `-c' option,
but always adds extra newline at the end of target file :-( . There is
small probability that remote `head' is not GNU head but supports all
our options. Let`s believe that it is "modern" head and it suits us! :-)
 


   The new variant of FISH uploads is successfully tested by us in
various environments (GNU-like, non-GNU) -- all works as it is expected.
 


   Appropriate patch attached.


-- 
		Dmitry K. Butskoj <dmitry at butskoj.name>
		Saint-Petersburg, Russia
		Red Hat Certified Engineer 809003662809495


-------------- next part --------------
A non-text attachment was scrubbed...
Name: mc-4.6.1-fish.patch
Type: text/x-patch
Size: 1765 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20041125/7e329f5a/attachment.bin>


More information about the mc-devel mailing list