/** * Delete the file */ public void delete() throws AccessDeniedException, NotfoundException { try { Files.delete(Paths.get(path)); } catch(NoSuchFileException e) { throw new LocalNotfoundException(String.format("Delete %s failed", path), e); } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot delete {0}", "Error"), this.getName()), e); } }
public Local getSymlinkTarget() throws NotfoundException { try { try { Paths.get(path).toRealPath(); } catch(NoSuchFileException ignore) { // Proceed if target is not found } catch(FileSystemException e) { // Too many levels of symbolic links log.warn(String.format("Failure resolving symlink target for %s. %s", path, e.getMessage())); throw new LocalNotfoundException(MessageFormat.format("Failure to read attributes of {0}", this.getName()), e); } // 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. final Path target = Files.readSymbolicLink(Paths.get(path)); if(target.isAbsolute()) { return LocalFactory.get(target.toString()); } else { return LocalFactory.get(this.getParent(), target.toString()); } } catch(InvalidPathException | IOException e) { throw new LocalNotfoundException(MessageFormat.format("Failure to read attributes of {0}", this.getName()), e); } }
private NSDictionary getNativeAttributes() throws AccessDeniedException, NotfoundException { if((!local.exists())) { throw new LocalNotfoundException(local.getAbsolute()); } final ObjCObjectByReference error = new ObjCObjectByReference(); // 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. final NSDictionary dict = NSFileManager.defaultManager().attributesOfItemAtPath_error( local.getAbsolute(), error); if(null == dict) { final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(local.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } return dict; }