Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jan 25, 2007
1 parent 975f569 commit e959cda
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
22 changes: 19 additions & 3 deletions source/ch/cyberduck/core/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import glguerin.io.Pathname;
import glguerin.io.imp.mac.macosx.MacOSXForker;

import ch.cyberduck.core.io.FileWatcher;
import ch.cyberduck.core.io.FileWatcherListener;

import com.apple.cocoa.application.NSWorkspace;
import com.apple.cocoa.foundation.NSBundle;
import com.apple.cocoa.foundation.NSDictionary;
Expand Down Expand Up @@ -134,6 +131,25 @@ public String getExtension() {
return null;
}

/**
* Checks whether a given file is a symbolic link.
*
* <p>It doesn't really test for symbolic links but whether the
* canonical and absolute paths of the file are identical - this
* may lead to false positives on some platforms.</p>
* @return true if the file is a symbolic link.
*/
public boolean isSymbolicLink() throws IOException {
if(!this.exists()) {
return false;
}
// For a link that actually points to something (either a file or a directory),
// the absolute path is the path through the link, whereas the canonical path
// is the path the link references.
return !this.getAbsolutePath().equals(this.getCanonicalPath());
}

/**
* @return the file type for the extension of this file provided by launch services
*/
Expand Down
61 changes: 50 additions & 11 deletions source/ch/cyberduck/core/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ protected Path(String parent, Local local) {
}

/**
* @param parent
* @param file
* @param parent The parent directory
* @param file The local file corresponding with this remote path
*/
public void setPath(String parent, Local file) {
this.setPath(parent, file.getName());
Expand All @@ -154,10 +154,11 @@ public void setPath(String parent, String name) {
}

/**
* @param p
* Normalizes the name before updatings this path. Resets its parent directory
* @param name Must be an absolute pathname
*/
public void setPath(String p) {
this.path = Path.normalize(p);
public void setPath(String name) {
this.path = Path.normalize(name);
this.parent = null;
}

Expand All @@ -174,6 +175,10 @@ public void setSymbolicLinkPath(String p) {
this.symbolic = p;
}

/**
* @see Attributes#isSymbolicLink
* @return The target of the symbolic link if this path denotes a symbolic link
*/
public String getSymbolicLinkPath() {
if(this.attributes.isSymbolicLink()) {
return this.symbolic;
Expand All @@ -182,7 +187,9 @@ public String getSymbolicLinkPath() {
}

/**
*
* Read the timestamp and size of this path from the remote server
* @see Attributes#setSize(double)
* @see Attributes#setTimestamp(long)
*/
public abstract void readAttributes();

Expand Down Expand Up @@ -291,7 +298,8 @@ public void invalidate() {

/**
* Request a unsorted and unfiltered file listing from the server.
*
* @see NullComparator
* @see NullPathFilter
* @return The children of this path or an empty list if it is not accessible for some reason
*/
public AttributedList list() {
Expand All @@ -316,6 +324,10 @@ public AttributedList cache() {
return (AttributedList) this.getSession().cache().get(this);
}

/**
* @see Cache
* @return True if this path denotes a directory and its file listing is cached for this session
*/
public boolean isCached() {
return this.getSession().cache().containsKey(this);
}
Expand Down Expand Up @@ -411,11 +423,28 @@ public String getAbsolute() {
}

/**
* Set the local equivalent of this path (used if downloaded or synced)
*
* Set the local equivalent of this path
* @param file
*/
public void setLocal(Local file) {
try {
if(file.isSymbolicLink()) {
/**
* A canonical pathname is both absolute and unique. The precise
* definition of canonical form is system-dependent. This method first
* converts this pathname to absolute form if necessary, as if by invoking the
* {@link #getAbsolutePath} method, and then maps it to its unique form in a
* system-dependent way. This typically involves removing redundant names
* such as <tt>"."</tt> and <tt>".."</tt> from the pathname, resolving
* symbolic links
*/
this.local = new Local(file.getCanonicalPath());
return;
}
}
catch(IOException e) {
log.error(e.getMessage());
}
this.local = file;
}

Expand All @@ -439,7 +468,7 @@ public Path getRemote() {
}

/**
* @return the extension if any
* @return the extension if any or null otherwise
*/
public String getExtension() {
String name = this.getName();
Expand Down Expand Up @@ -614,6 +643,10 @@ public boolean exists() {
return this.getParent().list().contains(this);
}

/**
* Returns the hashcode of #getAbsolute()
* @return
*/
public int hashCode() {
return this.getAbsolute().hashCode();
}
Expand Down Expand Up @@ -722,10 +755,16 @@ protected void finalize() throws java.lang.Throwable {
super.finalize();
}

/**
* @see Session#error(Path, String, Exception)
*/
protected void error(String message, IOException e) {
this.error(message, e, null);
this.getSession().error(this, message, e);
}

/**
* @see Session#error(Path, String, Exception, String)
*/
protected void error(String message, IOException e, String title) {
this.getSession().error(this, message, e, title);
}
Expand Down

0 comments on commit e959cda

Please sign in to comment.