public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH] lock: rewrite delete_lock_from_path_list
@ 2015-10-06  4:05 Mike Frysinger
  2015-10-06  6:43 ` Brian Dolbec
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2015-10-06  4:05 UTC (permalink / raw
  To: gentoo-catalyst

This code looks like it attempts to remove self.lockdir from the
lock_dirs_in_use list, but it doesn't seem to quite work:
 - it uses "for x in lock_dirs_in_use", but then indexes lock_dirs_in_use
   via the "i" variable
 - the "i" variable is set to 0, but then never incremented (looks like
   due to incorrect indentation)
 - the only way an entry would be deleted is if it happened to be in the
   first location of the list

In the end, this looks like an ad-hoc implementation of the list .remove
builtin, so just delete the code and use that.
---
 catalyst/lock.py | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/catalyst/lock.py b/catalyst/lock.py
index c031258..25d2aa2 100644
--- a/catalyst/lock.py
+++ b/catalyst/lock.py
@@ -57,15 +57,9 @@ class LockDir(object):
 		self.hardlock_paths={}
 
 	def delete_lock_from_path_list(self):
-		i=0
 		try:
-			if LockDir.lock_dirs_in_use:
-				for x in LockDir.lock_dirs_in_use:
-					if LockDir.lock_dirs_in_use[i] == self.lockdir:
-						del LockDir.lock_dirs_in_use[i]
-						break
-						i=i+1
-		except AttributeError:
+			LockDir.lock_dirs_in_use.remove(self.lockdir)
+		except ValueError:
 			pass
 
 	def islocked(self):
-- 
2.5.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-catalyst] [PATCH] lock: rewrite delete_lock_from_path_list
  2015-10-06  4:05 [gentoo-catalyst] [PATCH] lock: rewrite delete_lock_from_path_list Mike Frysinger
@ 2015-10-06  6:43 ` Brian Dolbec
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2015-10-06  6:43 UTC (permalink / raw
  To: gentoo-catalyst

On Tue,  6 Oct 2015 00:05:54 -0400
Mike Frysinger <vapier@gentoo.org> wrote:

> This code looks like it attempts to remove self.lockdir from the
> lock_dirs_in_use list, but it doesn't seem to quite work:
>  - it uses "for x in lock_dirs_in_use", but then indexes
> lock_dirs_in_use via the "i" variable
>  - the "i" variable is set to 0, but then never incremented (looks
> like due to incorrect indentation)
>  - the only way an entry would be deleted is if it happened to be in
> the first location of the list
> 
> In the end, this looks like an ad-hoc implementation of the
> list .remove builtin, so just delete the code and use that.
> ---
>  catalyst/lock.py | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/catalyst/lock.py b/catalyst/lock.py
> index c031258..25d2aa2 100644
> --- a/catalyst/lock.py
> +++ b/catalyst/lock.py
> @@ -57,15 +57,9 @@ class LockDir(object):
>  		self.hardlock_paths={}
>  
>  	def delete_lock_from_path_list(self):
> -		i=0
>  		try:
> -			if LockDir.lock_dirs_in_use:
> -				for x in LockDir.lock_dirs_in_use:
> -					if
> LockDir.lock_dirs_in_use[i] == self.lockdir:
> -						del
> LockDir.lock_dirs_in_use[i]
> -						break
> -						i=i+1
> -		except AttributeError:
> +			LockDir.lock_dirs_in_use.remove(self.lockdir)
> +		except ValueError:
>  			pass
>  
>  	def islocked(self):

great, Thanks...

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-06  6:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06  4:05 [gentoo-catalyst] [PATCH] lock: rewrite delete_lock_from_path_list Mike Frysinger
2015-10-06  6:43 ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox