• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Identifying Mac Aliases

 
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bd Howard
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bd Howard
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bd Howard
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic