From patchwork Wed Oct 31 09:20:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esben Haabendal X-Patchwork-Id: 195775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hugin.dotsrc.org (hugin.dotsrc.org [130.225.254.102]) by ozlabs.org (Postfix) with ESMTP id AA1C72C0193 for ; Wed, 31 Oct 2012 20:20:08 +1100 (EST) Received: from hugin.dotsrc.org (localhost [127.0.0.1]) by hugin.dotsrc.org (Postfix) with ESMTP id EE7053F837 for ; Wed, 31 Oct 2012 10:20:05 +0100 (CET) X-Original-To: dev@oe-lite.org Delivered-To: dev@oe-lite.org Received: from mail02.prevas.se (mail02.prevas.se [62.95.78.10]) by hugin.dotsrc.org (Postfix) with ESMTPS id CA7453F837 for ; Wed, 31 Oct 2012 10:20:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=3503; q=dns/txt; s=ironport2; t=1351675203; x=1383211203; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=j3W3/sJNDIntyrHDs+pAqEPcHKgIZWpuuoPyY92s/8M=; b=LRF/XfU9Dh0d8OQcX+l+jgHsW+TUQtp3rd29Iv6sj89KLmjd55tncudn Kuiji7P4pMR1rseqRE9wa3iunzKrSOQ98v/NWjry/RDj8/qH+l9S964Xz cJT3YExsElYYvSM; X-IronPort-AV: E=Sophos;i="4.80,687,1344204000"; d="scan'208";a="1768212" Received: from vmprevas3.prevas.se (HELO smtp.prevas.se) ([172.16.8.103]) by ironport2.prevas.se with ESMTP/TLS/AES128-SHA; 31 Oct 2012 10:20:03 +0100 Received: from dev.prevas.dk (172.16.10.60) by smtp.prevas.se (172.16.8.105) with Microsoft SMTP Server (TLS) id 14.2.318.1; Wed, 31 Oct 2012 10:20:02 +0100 Received: from arh128 (0x55532124.adsl.cybercity.dk [85.83.33.36]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: eha) by dev.prevas.dk (Postfix) with ESMTPSA id 935697FF5A; Wed, 31 Oct 2012 10:20:02 +0100 (CET) Received: by arh128 (Postfix, from userid 1000) id B59A28027E; Wed, 31 Oct 2012 10:20:01 +0100 (CET) From: Esben Haabendal To: Morten Thunberg Svendsen Subject: Re: [oe-lite] [PATCH 08/10] task.py: When the dir to clean is a symlink rmtree fails. Catch the error and unlink References: <20f518f91233d0b76b33426cd66266d142c7a21b.1328775714.git.moth@prevas.dk> <87fwekl4kc.fsf@arh128.dev.prevas.dk> <4F339813.2080808@prevas.dk> <87hayss018.fsf@arh128.dev.prevas.dk> Date: Wed, 31 Oct 2012 10:20:01 +0100 In-Reply-To: <87hayss018.fsf@arh128.dev.prevas.dk> (Esben Haabendal's message of "Wed, 15 Feb 2012 14:23:31 +0100") Message-ID: <87ip9rf16m.fsf@arh128.prevas.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Cc: dev@oe-lite.org X-BeenThere: dev@oe-lite.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: OE-lite development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dev-bounces@oe-lite.org Errors-To: dev-bounces@oe-lite.org Esben Haabendal writes: > Morten Thunberg Svendsen writes: > >> On 2012-02-09 10:49, Esben Haabendal wrote: >>> Morten Thunberg Svendsen writes: >>> >>>> From: Morten Thunberg Svendsen >>>> >>>> archive-image.oeclass creates symlink, and if archiving fails it remains >>>> until next build and the rmtree would fail. >>>> --- >>>> lib/oelite/task.py | 2 ++ >>>> 1 files changed, 2 insertions(+), 0 deletions(-) >>>> >>>> diff --git a/lib/oelite/task.py b/lib/oelite/task.py >>>> index 47d83d7..d0b01ea 100644 >>>> --- a/lib/oelite/task.py >>>> +++ b/lib/oelite/task.py >>>> @@ -278,6 +278,8 @@ class OEliteTask: >>>> try: >>>> #print "cleandir %s"%(cleandir) >>>> shutil.rmtree(cleandir) >>>> + except OSError: >>>> + os.unlink(cleandir) >>>> except Exception, e: >>>> err("cleandir %s failed: %s"%(cleandir, e)) >>>> raise >>> >>> Could there be other OSError exceptions? >> >> Only the symlink error is mentioned in the manual > >>>> import shutil >>>> shutil.rmtree("/tmp") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/shutil.py", line 244, in rmtree > rmtree(fullname, ignore_errors, onerror) > File "/usr/lib/python2.7/shutil.py", line 253, in rmtree > onerror(os.rmdir, path, sys.exc_info()) > File "/usr/lib/python2.7/shutil.py", line 251, in rmtree > os.rmdir(path) > OSError: [Errno 1] Operation not permitted: '/tmp/.ICE-unix' > >>>> import shutil >>>> shutil.rmtree("/FOO/BAR") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/shutil.py", line 236, in rmtree > onerror(os.listdir, path, sys.exc_info()) > File "/usr/lib/python2.7/shutil.py", line 234, in rmtree > names = os.listdir(path) > OSError: [Errno 2] No such file or directory: '/FOO/BAR' > > So there are at least 2 more. Perhaps better to do something like > > if os.path.islink(cleandir): > os.unlink(cleandir) > else: > try: > shutil.rmtree(cleandir) > .... > > Would be better. Better late than never. I pushed a fix for this to master and 3.2 branches. commit fc81f8044cd404eb4e33cae6ef20cc7d292a0570 Author: Esben Haabendal Date: Wed Oct 31 08:48:45 2012 +0100 lib/oelite: Handle cleandir on symlinks Handle cases where cleandir refers to a symlink, which fx. can happen after failure in do_compile when using archive-image class. Signed-off-by: Esben Haabendal /Esben diff --git a/lib/oelite/task.py b/lib/oelite/task.py index 5dac890..0db4303 100644 --- a/lib/oelite/task.py +++ b/lib/oelite/task.py @@ -266,7 +266,10 @@ class OEliteTask: continue try: #print "cleandir %s"%(cleandir) - shutil.rmtree(cleandir) + if os.path.islink(cleandir): + os.unlink(cleandir) + else: + shutil.rmtree(cleandir) except Exception, e: err("cleandir %s failed: %s"%(cleandir, e)) raise