Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 150163 - A minor change in new_protect_filename() in portage_util.py
Summary: A minor change in new_protect_filename() in portage_util.py
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: High trivial (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 147007
  Show dependency tree
 
Reported: 2006-10-05 06:10 UTC by Ali Polatel (RETIRED)
Modified: 2006-10-06 04:43 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Polatel (RETIRED) gentoo-dev 2006-10-05 06:10:22 UTC
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; tr; rv:1.8.0.6) Gecko/20060808 Firefox/1.5.0.6
Build Identifier: 

 Here is a minor change in new_protect_filename() in portage_util.py
(starting from line 908 on portage version 2.1.2_pre2-r2)
"""
if len(mydest) == 0:
	raise ValueError, "Empty path provided where a filename is required"
if mydest[-1] == os.path.sep: # XXX add better directory checking
	raise ValueError, "Directory provided but this function requires a filename" 
"""
This can be changed to:
"""
if not mydest:
	raise ValueError, "Empty path..."
if os.path.isdir(mydest):
	raise ValueError, "Directory provided..."
"""



Reproducible: Always

Steps to Reproduce:
Comment 1 yogeshbug 2006-10-05 06:15:14 UTC
You have not specified why you wanna change portage_util.py so pls explain
Comment 2 Zac Medico gentoo-dev 2006-10-05 06:23:48 UTC
The calling code should have checked that stuff already.  That makes your check redundant and it's annoying to have a bunch of redundant checks in the code.
Comment 3 Ali Polatel (RETIRED) gentoo-dev 2006-10-05 06:45:09 UTC
 Well basically , the function os.path.isdir() is native and I think it's better to use it instead of 'mydest[-1] == os.path.sep'.Actually this the only place where os.path.sep is used to check for a directory afaik.All other functions use os.path.isdir()
 About the other change , 'not mydest' is faster than the len() call.To be honest, this is usually at microseconds level but why not use the faster?
 And about what Zac said , I agree that it's annoying to have redundant checks in the code.I didn't have time to check if the calling code do the checks.If so the checks in new_protect_filename() are not needed and should be removed.
Comment 4 Zac Medico gentoo-dev 2006-10-05 18:28:24 UTC
In svn r4601 I've removed all the the validation of parameters because portage doesn't need it.  Please note that os.path.isdir(mydest) results in a stat call, and unnecessary stat calls should be avoided.
Comment 5 Zac Medico gentoo-dev 2006-10-06 04:43:05 UTC
This has been released in 2.1.2_pre2-r5.