[PATCH] When applying a git diff, ensure that the target dir exists for new files

Stefan Rusek stefan at rusek.org
Tue Dec 9 17:03:09 CST 2008


>>
>> -    if not os.path.isdir(basedir):
>> -        os.makedirs(basedir)
>> +    dstdir = os.path.dirname(absdst)
>> +    if dstdir and not os.path.exists(dstdir):
>
> Any reason to prefer os.path.exists() to isdir() here ? I prefer the latter, makedirs() is likely to die sooner and for more obvious reasons.
> Otherwise the patch is good for me, and I have a test ready.
>
>> +        os.makedirs(dstdir)
>>

Here are the two error messages (on windows)
makdirs - "The system cannot find the path specified: <badpath>"
copyfile - "No such file or directory: <badpath>"

So they both give the same error, though makdirs gives a complete
sentence, neither is a useful error message. Maybe it should do this:

if dstdir and not os.path.isdir(dstdir):
  try:
    os.makedirs(dstdir)
  except:
    raise util.Abort(_("cannot create %s: unable to create destination
directory") % dst)

This way the user gets a shove in the right direction.


More information about the Mercurial-devel mailing list