[Zope] Re: LocalFS cross platform bug

Jonothan Farr jfarr@real.com
Mon, 19 Jun 2000 14:19:11 -0700


This is a known bug. Thanks for the patch. The problem with it is that filenames
containing backslash characters are valid on Unix. I haven't been able to come
up with a solution to this. Any ideas?

--jfarr

"Perl is worse than Python because people wanted it worse."
Larry Wall, 14 Oct 1998

----- Original Message -----
From: Dan L. Pierson <dan@sol.control.com>
To: <zope@zope.org>
Sent: Thursday, June 15, 2000 12:58 PM
Subject: [Zope] LocalFS cross platform bug


> If you upload from a browser on a Windows machine to a server running
> on Linux, the id (and thus the file name) of the new file will be the
> complete Windows path instead of just the file name.  This happens
> because os.basename on Linux doesn't know how to handle Windows
> pathname syntax.
>
> Here's a rather crude diff -u patch that works for me:
>
> --- LocalFS.py-orig     Fri Apr 14 00:36:06 2000
> +++ LocalFS.py  Thu Jun 15 15:36:19 2000
> @@ -625,10 +625,16 @@
>                      "to this directory.<p>")
>              else: raise
>
> +    def _canonicalize_pathname(self, path):
> +        if (string.count(path, '\\')):
> +            if (len(path) > 1 and path[0] in string.letters and path[1] ==
':'):
> +                path = path[2:]
> +            path = string.translate(path, string.maketrans('\\', '/'))
> +
>      def manage_upload(self, file, REQUEST=None):
>          """Upload a file to the local file system. The 'file' parameter
>          is a FileUpload instance representing the uploaded file."""
> -        id = os.path.basename(file.filename)
> +        id = os.path.basename(self._canonicalize_pathname(file.filename))
>          path = self._getpath(id)
>          data = file.read(_test_read)
>          if (find_binary(data) >= 0):
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>