~sschwarzer/ftputil#22: 
makedirs creates absolute path in working dir instead of root dir

#Info

ftputil version: 2.2.2
python: 2.5.1
ftpserver: any, (i used proftpd on localhost)
OS: Linux julian-laptop 2.6.20-16-generic #2 SMP Thu Jun 7 20:19:32 UTC 2007 i686 GNU/Linux

#Bug

makedirs(self, path) creates the whole path, but doesn't start in root dir but in the current working dir (cwd).
no traceback is possible as no errors occur

#Code example

import ftputil
h = ftputil.FTPHost(server, name, password)
# cwd=/

# assuming root dir of host has an empty directory foo
h.chdir('foo') 
# cwd=/foo

h.makedirs('bar/helloworld')
# this should have created /foo/bar/helloworld
# instead it created /foo/foo/bar/helloworld

h.makedirs('/meaning/of/life')
# this should have created /meaning/of/life
# instead it created /foo/meaning/of/life

#Problem origin

in ftputil.py, function makedirs(self, path, mode=None)

because of

path = self.path.abspath(path)
directories = path.split(self.sep)

path must start with '/' char (root dir), leaving directories as a list with first element an empty string.
then, later next_directory will be constructed as

next_directory = self.path.join(*directories[:index+1])

next_directory will never be an absolute path but a relative one.

#Solution

change line 611 in fptutil/ftputil.py

next_directory = self.sep + self.path.join(*directories[:index+1])

btw, thanks for the great module!

julian

Status
RESOLVED FIXED
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
17 years ago
Updated
17 years ago
Labels
bug library

schwa (unverified) 17 years ago ยท edit

Hi Julian,

It seems you're right. :-) I added some test code and your fix to the trunk (in changeset 713). Thanks for not only reporting the bug but investigating it and providing a fix, too.

Register here or Log in to comment, or comment via email.