[bitbake-devel] [PATCH] utils: Use rm -rf in remove()

Martin Ertsås martiert at gmail.com
Sat Feb 16 15:27:31 UTC 2013


On 02/16/13 15:54, Richard Purdie wrote:
> On Sat, 2013-02-16 at 14:51 +0100, Martin Ertsås wrote:
>> On 02/15/13 17:00, Richard Purdie wrote:
>>> On Thu, 2013-02-07 at 18:08 -0700, Chris Larson wrote:
>>>> On Thu, Feb 7, 2013 at 4:55 PM, Richard Purdie
>>>> <richard.purdie at linuxfoundation.org> wrote:
>>>>           -                shutil.rmtree(name)
>>>>           +                # shutil.rmtree(name) would be ideal but its
>>>>           too slow
>>>>           +                subprocess.call('rm -rf %s' % path,
>>>>           shell=True)
>>>>
>>>> This is a good idea, but I'm curious about forking off a shell process
>>>> for it. I'd think this would work as well: subprocess.call(['rm',
>>>> '-rf', path])
>>> path can have wildcards in it. The code wasn't entirely obvious so I've
>>> tweaked it after your/Peter's comments. I'm hoping it will help the
>>> problems Martin was seeing too.
>>>
>>> Cheers,
>>>
>>> Richard
>>>
>>>
>> I think this is a good idea as well. One thing I would question though,
>> is to have this in the except clause. Why not:
>>
>>       for name in glob.glob(path):
>>           try:
>> 	    if recurse and os.path.isdir(path):
>> 	       subprocess.call('rm -rf %s' % path, shell=True)
>> 	       return
>> 	    os.unlink(name)
>>           except OSError as exc:
>>               if exc.errno != errno.ENOENT:
>>                   raise
>>
>>
>> Personally I feel it is cleaner to have all the remove possibilities in
>> the try, and let the exceptions be in except. Kind of feel it is wrong
>> to let the recursive case be handled in the exception, as I don't see it
>> being an exceptional case to delete a folder.
>>
>> Also, unfortunately your patch would not fix osx, as EISDIR is not the
>> error that is returned there. What I get is either a EPERM or an EACCES
>> (not on a mac now, so can't check it until monday). So osx would still
>> fall through to the raise.
> Can you take a look at the patch I ended up committing? Its basically as
> you describe above expect I moved the subprocess outside the for loop as
> well.
>
> (http://git.openembedded.org/bitbake/commit/?id=96088ebdec08e49ba9e8dbcac437bfcdc21f5983)
>
> Cheers,
>
> Richard
>
>
>
That is great! Will fix up the mac problems without any problems, at 
least it looks like. I'll try it out on monday, and come back 
complaining if it doesn't fix it ;)

- Martin




More information about the bitbake-devel mailing list