Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#22 closed defect (fixed)

makedirs creates absolute path in working dir instead of root dir

Reported by: ftputiluser Owned by: schwa
Priority: major Milestone: 2.2.3
Component: Library Version: 2.2.2
Keywords: makedirs, path Cc:

Description (last modified by schwa)


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


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
# cwd=/foo

# this should have created /foo/bar/helloworld
# instead it created /foo/foo/bar/helloworld

# this should have created /meaning/of/life
# instead it created /foo/meaning/of/life

Problem origin

in, 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.


change line 611 in fptutil/

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

btw, thanks for the great module!


Change History (3)

comment:1 Changed 14 years ago by schwa

Keywords: makedirs path added
Status: newassigned
Version: 2.2.2

comment:2 Changed 14 years ago by schwa

Description: modified (diff)
Resolution: fixed
Status: assignedclosed
Summary: makedirs creates abs. path in working dir instead of rootmakedirs creates absolute path in working dir instead of root dir

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.

comment:3 Changed 12 years ago by schwa

Milestone: 2.2.3
Note: See TracTickets for help on using tickets.