Opened 11 years ago

Closed 11 years ago

Last modified 10 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)

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

Change History (3)

comment:1 Changed 11 years ago by schwa

  • Keywords makedirs path added
  • Status changed from new to assigned
  • Version set to 2.2.2

comment:2 Changed 11 years ago by schwa

  • Description modified (diff)
  • Resolution set to fixed
  • Status changed from assigned to closed
  • Summary changed from makedirs creates abs. path in working dir instead of root to makedirs 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 10 years ago by schwa

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