Skip to content

Commit

Permalink
Use inode when comparing for equality of paths. #3018.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jul 28, 2010
1 parent 5fc9e25 commit f6ae7e1
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions source/ch/cyberduck/ui/cocoa/model/FinderLocal.java
Expand Up @@ -107,7 +107,7 @@ public void setPath(String parent, String name) {
// See trac #933
name = name.replace(this.getPathDelimiter(), ':');
}
super.setPath(parent, name);
super.setPath(parent, name);
}

/**
Expand Down Expand Up @@ -179,8 +179,8 @@ private class FinderLocalAttributes extends LocalAttributes {
@Override
public Permission getPermission() {
try {
NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributes(
_impl.getAbsolutePath());
NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributesAtPath_traverseLink(
_impl.getAbsolutePath(), false);
if(null == fileAttributes) {
log.error("No such file:" + getAbsolute());
return null;
Expand All @@ -207,7 +207,8 @@ public Permission getPermission() {
*/
@Override
public long getCreationDate() {
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributes(_impl.getAbsolutePath());
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributesAtPath_traverseLink(
_impl.getAbsolutePath(), false);
// If flag is true and path is a symbolic link, the attributes of the linked-to file are returned;
// if the link points to a nonexistent file, this method returns null. If flag is false,
// the attributes of the symbolic link are returned.
Expand All @@ -231,7 +232,8 @@ public long getAccessedDate() {

@Override
public String getOwner() {
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributes(_impl.getAbsolutePath());
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributesAtPath_traverseLink(
_impl.getAbsolutePath(), false);
// If flag is true and path is a symbolic link, the attributes of the linked-to file are returned;
// if the link points to a nonexistent file, this method returns null. If flag is false,
// the attributes of the symbolic link are returned.
Expand All @@ -250,7 +252,8 @@ public String getOwner() {

@Override
public String getGroup() {
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributes(_impl.getAbsolutePath());
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributesAtPath_traverseLink(
_impl.getAbsolutePath(), false);
// If flag is true and path is a symbolic link, the attributes of the linked-to file are returned;
// if the link points to a nonexistent file, this method returns null. If flag is false,
// the attributes of the symbolic link are returned.
Expand All @@ -266,18 +269,36 @@ public String getGroup() {
}
return group.toString();
}

/**
* @return The value for the key NSFileSystemFileNumber, or 0 if the receiver doesn’t have an entry for the key
*/
public long getInode() {
final NSDictionary fileAttributes = NSFileManager.defaultManager().fileAttributesAtPath_traverseLink(
_impl.getAbsolutePath(), false);
// If flag is true and path is a symbolic link, the attributes of the linked-to file are returned;
// if the link points to a nonexistent file, this method returns null. If flag is false,
// the attributes of the symbolic link are returned.
if(null == fileAttributes) {
log.error("No such file:" + getAbsolute());
return 0;
}
NSNumber number = Rococoa.cast(fileAttributes.objectForKey(NSFileManager.NSFileSystemFileNumber), NSNumber.class);
return number.longValue();
}
}

@Override
public LocalAttributes attributes() {
public FinderLocalAttributes attributes() {
if(null == attributes) {
attributes = new FinderLocalAttributes();
}
return attributes;
}

/**
* @return Human readable description of file type
* @return The file type for the extension of this file provided by launch services
* if the path is a file.
*/
@Override
public String kind() {
Expand Down Expand Up @@ -375,6 +396,27 @@ public void touch(boolean recursive) {
super.touch(recursive);
}

/**
* Comparing by inode if the file exists.
*
* @param o
* @return
*/
@Override
public boolean equals(Object o) {
if(o instanceof FinderLocal) {
if(!this.exists()) {
return super.equals(o);
}
FinderLocal other = (FinderLocal) o;
if(!other.exists()) {
return super.equals(o);
}
return this.attributes().getInode() == other.attributes().getInode();
}
return super.equals(o);
}

/**
* @param originUrl The URL of the resource originally hosting the quarantined item, from the user's point of
* view. For web downloads, this property is the URL of the web page on which the user initiated
Expand Down

0 comments on commit f6ae7e1

Please sign in to comment.