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:
You have not specified why you wanna change portage_util.py so pls explain
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.
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.
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.
This has been released in 2.1.2_pre2-r5.