[Python-bugs-list] [ python-Bugs-543464 ] ResolveAliasFile problem

noreply@sourceforge.net noreply@sourceforge.net
Sat, 13 Apr 2002 11:47:52 -0700


Bugs item #543464, was opened at 2002-04-13 13:47
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=543464&group_id=5470

Category: Macintosh
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Submitted By: Christopher Smith (smichr)
Assigned to: Jack Jansen (jackjansen)
Summary: ResolveAliasFile problem

Initial Comment:
ResolveAliasFile (and other macfs functions) are 
not as robust as macpath functions when it comes 
to testing a path containing an alias.

For example, path s shown below is the path to the 
file 'macintosh hd:desktop folder:k:' generated 
during a walk of folder f.  h is an alias in f that 
points to a desktop folder named h; ka is an alias 
within h that points to the folder k on the desktop.

While exists() can tell that it exists, an alias 
resolution fails as the following interactive 
sessions shows:

>>> s
'macintosh hd:desktop folder:f:h:ka:'
>>> macpath.exists(s)
1
>>> macpath.isdir(s)
1
>>> macpath.isfile(s)
0
>>> macfs.ResolveAliasFile(s)
Traceback (most recent call last):
  File "<input>", line 1, in ?
MacOS.Error: (-120, 'Directory not found')

The folder does exist, though, and can be resolved 
if the reference to f is bypassed in the path:

>>> macfs.ResolveAliasFile('macintosh 
hd:desktop folder:k')
(FSSpec((-1, 16, 'K')), 1, 0)

The resolution of anything in folder h fails.  Here I 
try to resolve the fss to the file h1 that exists in h:

>>> macfs.ResolveAliasFile('macintosh 
hd:desktop folder:f:h:h1')
Traceback (most recent call last):
  File "<input>", line 1, in ?
MacOS.Error: (-120, 'Directory not found')

When I bypass folder f in the path, the fss is 
returned:
>>> macfs.ResolveAliasFile('macintosh 
hd:desktop folder:h:h1')
(FSSpec((-1, 184613, 'h1')), 0, 0)

The same trouble plagues macfs.copy:

>>> p='macintosh hd:desktop folder:'
>>> macostools.copy(p+'k:jnk',p+'test') #this works
>>> macostools.copy(p+"h:ka:jnk",p+'test') #fails
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "Macintosh HD:Applications (Mac OS 
9):Python 2.2:Mac:Lib:macostools.py", line 85, in 
copy
    srcfss = macfs.FSSpec(src)
MacOS.Error: (-120, 'Directory not found')

A workaround that I have used is to create a 
resolve() function that rebuilds the path one 
element at a time, resolving elements along the 
way so a valid path is finally obtained:

def resolve(s, justPath=0):
	"""Get an absolute path from this possibly 
convoluted path that would give ResolveAliasFile 
problems.
	If justPath=1 then only the path up to the last entity 
in the path will be resolved, otherwise the
	whole path will be resolved and you will have the 
actual path to the item if it exists on disk.  If the
	file does not exist, an error is raised."""
	#
	# If you resolve all but the last item in the s then 
you will be able to call
	# resolveAliasFile and find out if the thing is an 
alias or not, otherwise you 
	# will have resolved the entire path to a real item if 
it exists.
	#
	p=abspath(s).split(":")
	
	# Define the indice to use so slices below will (or 
will not) include
	# the last element in the path.
	if justPath:
		last=-1
	else:
		last=len(p)
		
	rv=p[0]+":"
	for pi in p[1:last]:
		try:
			d=join(rv,pi)
			rv=macfs.ResolveAliasFile(d)[0].as_pathname()
		except:
			raise "File not found."
			
	return  join(rv,p[last:])




----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=543464&group_id=5470