[bitbake-devel] [PATCH] utils.py: Use shutil.rmtree if the path we wish to remove is a directory.
Chris Larson
clarson at kergoth.com
Thu Jan 10 14:18:13 UTC 2013
On Thu, Jan 10, 2013 at 7:11 AM, Chris Larson <clarson at kergoth.com> wrote:
>
> On Thu, Jan 10, 2013 at 7:10 AM, Chris Larson <clarson at kergoth.com> wrote:
>
>> On Thu, Jan 10, 2013 at 1:46 AM, Martin Ertsaas <martiert at gmail.com>wrote:
>>
>>> On mac, os.unlink does not remove directories, and we therefor have
>>> to explicitly use shutil.rmtree if the path is a directory.
>>> ---
>>> lib/bb/utils.py | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
>>> index cef0fdd..8b6d3f5 100644
>>> --- a/lib/bb/utils.py
>>> +++ b/lib/bb/utils.py
>>> @@ -561,7 +561,10 @@ def remove(path, recurse=False):
>>> import os, errno, shutil, glob
>>> for name in glob.glob(path):
>>> try:
>>> - os.unlink(name)
>>> + if os.path.isdir(name):
>>> + shutil.rmtree(name)
>>> + else:
>>> + os.unlink(name)
>>> except OSError as exc:
>>> if recurse and exc.errno == errno.EISDIR:
>>> shutil.rmtree(name)
>>>
>>
>>
>> Look 2 lines down, where it checks to see if the os.unlink failed due to
>> it being a directory and runs shutil.rmtree if that's the case.
>
>
> I'm guessing you're trying to use it without passing recurse=True.
Having through about it further, I think it might be best to be alter the
code to also handle the case where recurse==False and the path is a
directory by calling os.rmdir(). Perhaps this would reduce confusion.
--
Christopher Larson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/bitbake-devel/attachments/20130110/02cc64ef/attachment-0001.html>
More information about the bitbake-devel
mailing list