@Override public FilePermissions getPermissions() { if(isSymlink()) return getCanonicalFile().getAncestor(FTPFile.class).permissions; return permissions; }
@Override public long getDate() { if(isSymlink()) return ((org.apache.commons.net.ftp.FTPFile)getCanonicalFile().getUnderlyingFileObject()).getTimestamp().getTimeInMillis(); return file.getTimestamp().getTimeInMillis(); }
@Override public long getSize() { if(isSymlink()) return ((org.apache.commons.net.ftp.FTPFile)getCanonicalFile().getUnderlyingFileObject()).getSize(); return file.getSize(); }
@Override public AbstractFile getCanonicalFile() { if(!isSymlink()) return this; // Create the canonical file instance and cache it if(canonicalFile==null) { // getLink() returns the raw symlink target which can either be an absolute or a relative path. If the path is // relative, preprend the absolute path of the symlink's parent folder. String symlinkTargetPath = file.getLink(); if(!symlinkTargetPath.startsWith("/")) { String parentPath = fileURL.getParent().getPath(); if(!parentPath.endsWith("/")) parentPath += "/"; symlinkTargetPath = parentPath + symlinkTargetPath; } FileURL canonicalURL = (FileURL)fileURL.clone(); canonicalURL.setPath(symlinkTargetPath); canonicalFile = FileFactory.getFile(canonicalURL); } return canonicalFile; }
@Override public boolean isDirectory() { // org.apache.commons.net.ftp.FTPFile#isDirectory() returns false if the file is a symlink pointing to a // directory, this is a limitation of the Commons-net library. // Todo: fix this by either: // a) find a combination of 'LIST' switches which allows the output to contain both the 'is symlink' and the // 'is the symlink target a directory' information. At a first glance, there doesn't seem to be one: either // symlinks are followed or there aren't. // b) Patch #ls() to issue an extra 'LIST -ldH *' to retrieve all symlinks' information when the directory has // at least one symlink. // c) if this file is a symlink, retrieve the symlink's target using #getFTPFile(FileURL) with '-ldH' switches // and return the value of isDirectory(). This clearly is the least effective solution at it requires issuing // one 'ls' command per symlink. if(isSymlink()) return ((org.apache.commons.net.ftp.FTPFile)getCanonicalFile().getUnderlyingFileObject()).isDirectory(); return file.isDirectory(); }