wood burning stoves 2.0*
The moose likes Mac OS and the fly likes Identifying Mac Aliases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Identifying Mac Aliases" Watch "Identifying Mac Aliases" New topic
Author

Identifying Mac Aliases

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hi,

I am using Lion and I've got a simple Java app where the user can drop files/folders onto it.

What distinguishes an alias (on the desktop for example) from a normal file? When I call the .isFile() it returns true and .isDirectory() returns false even when the alias points to a directory with only other directories in it. The error I am getting occurs when I try to call file.toPath(). The code works fine with regular files and directories. Throw in an alias and it breaks.

I'd like to find out how I can "follow" the alias whenever I come across one via the drag & drop.

I am using 1.7 along with the SimpleFileVisitor to walk the trees.

Thanks for the help

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hi,

I did a search, and found something using the Canonical path, but that did not get me what I am looking for, which is just a bit of code that I can feed a file reference to and determine if that file is in fact an alias. I tried using length() and that returns the same number for both aliases and directories.

Don't want to step on toes, but I think I am not being too hasty in bumping this thread. :-)

Thank you,

BD
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Perhaps if I explain my problem instead of just what I am looking for, someone may have an idea on how to help me.

When scanning the entire drive with Java 7's SimpleFileVisitor, if one of my subdirectories has an alias to another directory, the Visitor enters a loop and never exits. By that I mean when it follows the alias, it visits the same folders it visited the first time it followed that alias. Then it hits that alias again and starts reading that tree all over.

I thought if I could test for an alias, I could avoid this behavior. I thought about just keeping a list of each directory searched, but that wouldn't work since each loop of that alias would simply add to the path, resulting in a unique path.

I found a work-a-round to avoid this, but it makes my program less useful, so I'd like to fix this right, through a test for the alias.

The error I described in the first post of this thread is no longer an issue due to a code change.



Thanks all,

BD
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

I don't use a Mac (never even seen one up close) but can you Runtime#exec(...) ls -l and capture the output? And is the first character of that output 'l' (lowercase ell) for an alias, as it is for a symbolic link in Unix?


luck, db
There are no new questions, but there may be new answers.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Darryl Burke wrote:I don't use a Mac (never even seen one up close) but can you Runtime#exec(...) ls -l and capture the output? And is the first character of that output 'l' (lowercase ell) for an alias, as it is for a symbolic link in Unix?


I will try this and see.

How much "cost" is there to doing a call to Runtime for each file on the drive? By that I mean is it prohibitive in terms of how much time that will add to the running of the program? I guess there is one easy way to find out, huh? :-)

I was just messing around in Terminal using the ls command, and it seems that an alias lists what it is pointing to (at least in terms of the file size) without any telltale flags that identify it as an alias. Symbolic links on the other hand are easy to see and differentiate. Come to think of it, the issue I've described above may be because of a symbolic link instead of an alias. I seem to recall that Macs handle those differently even though they are essentially the same thing in the abstract. I could be wrong about this, and would appreciate a correction if necessary.

Thanks for the tip Darryl. :-)

BD
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

Bd Howard wrote:I was just messing around in Terminal using the ls command, and it seems that an alias lists what it is pointing to (at least in terms of the file size) without any telltale flags that identify it as an alias. Symbolic links on the other hand are easy to see and differentiate. Come to think of it, the issue I've described above may be because of a symbolic link instead of an alias.

Ouch. I didn't even know that they weren't the same thing.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Yes, they are different. Here's a capture from an ls -l command that shows three different types:

The first is a symbolic link, the second a folder, the third an Alias to that folder.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I don't claim to be any type of expert on this, (or anything else for that matter), but it is my understanding that they are similar, but different. At least how the Mac handles them is different.

Hopefully someone will set me straight if I'm off base here.

Anyway, you did say you've never seen a Mac up close. Seems like a perfect opportunity to become acquainted though. Careful though, you might like it and become an anathema to all your friends. :-D
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Bear Bibeault wrote:Yes, they are different. Here's a capture from an ls -l command that shows three different types:

The first is a symbolic link, the second a folder, the third an Alias to that folder.


Notice that "@" symbol on the line for the alias? I thought I could use that, but I have a few png files on my desktop that also have that @ symbol.

The symbolic links have a "->" so they are easy to spot.

BD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Bd Howard wrote:I don't claim to be any type of expert on this, (or anything else for that matter), but it is my understanding that they are similar, but different. At least how the Mac handles them is different.

Yes. Aliases have been a part of the Mac file system since the dawn of the Ice Age. Symbolic links are a Unix file system concept. They are different ways of doing (almost) the same thing.

Anyway, you did say you've never seen a Mac up close.

That was Darryl, not me. I've been working with Macs since the Eocene Epoch.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Yes, we are interleaving our responses. That Mac comment was directed at Darryl. Perhaps we can turn him to the Dark Side. :-)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

Bd Howard wrote:Perhaps we can turn him to the Dark Side. :-)

Not likely If I'd envisaged getting a Mac, I wouldn't have started a thread here a week ago.
 
 
subject: Identifying Mac Aliases
 
Similar Threads
Directory lengths
How do I run an unix script?
K&B pg 805
How do I run an unix script?
Discrepancy in listing of a file using Windows Explorer and JAVA I/O classes