@Before public void setPathHelper() throws Exception { PathHelper helper = new PathHelper(new PathHelper.Canonicalizer() { /** * Very basic, it does not try to canonicalize relative bits in the middle of a path. */ @Override public String canonicalize(String path) throws IOException { if ("".equals(path) || ".".equals(path) || "./".equals(path)) return "/home/me"; if ("..".equals(path) || "../".equals(path)) return "/home"; return path; } }, DEFAULT_PATH_SEPARATOR); when(sftpEngine.getPathHelper()).thenReturn(helper); when(sftpEngine.stat("/")).thenReturn(new FileAttributes.Builder().withType(FileMode.Type.DIRECTORY).build()); when(sftpEngine.getLoggerFactory()).thenReturn(LoggerFactory.DEFAULT); }
@Before public void setRemoteWorkingDirectory() throws IOException { FileAttributes isADirectory = new FileAttributes.Builder().withType(FileMode.Type.DIRECTORY).build(); when(sftpEngine.stat("/workingdirectory")).thenReturn(isADirectory); }
@Override public void setUnixOwner(final Path file, final String owner) throws BackgroundException { final FileAttributes attr = new FileAttributes.Builder() .withUIDGID(new Integer(owner), 0) .build(); try { session.sftp().setAttributes(file.getAbsolute(), attr); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
public void chmod(String path, int perms) throws IOException { setattr(path, new FileAttributes.Builder().withPermissions(perms).build()); }
public void truncate(String path, long size) throws IOException { setattr(path, new FileAttributes.Builder().withSize(size).build()); }
public void chmod(String path, int perms) throws IOException { setattr(path, new FileAttributes.Builder().withPermissions(perms).build()); }
@Override public void setUnixPermission(final Path file, final Permission permission) throws BackgroundException { final FileAttributes attr = new FileAttributes.Builder() .withPermissions(Integer.parseInt(permission.getMode(), 8)) .build(); try { session.sftp().setAttributes(file.getAbsolute(), attr); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
public void chgrp(String path, int gid) throws IOException { setattr(path, new FileAttributes.Builder().withUIDGID(uid(path), gid).build()); }
private FileAttributes getAttributes(LocalSourceFile local) throws IOException { final FileAttributes.Builder builder = new FileAttributes.Builder().withPermissions(local.getPermissions()); if (local.providesAtimeMtime()) builder.withAtimeMtime(local.getLastAccessTime(), local.getLastModifiedTime()); return builder.build(); }
private FileAttributes getAttributes(LocalSourceFile local) throws IOException { final FileAttributes.Builder builder = new FileAttributes.Builder().withPermissions(local.getPermissions()); if (local.providesAtimeMtime()) builder.withAtimeMtime(local.getLastAccessTime(), local.getLastModifiedTime()); return builder.build(); }
public void chown(String path, int uid) throws IOException { setattr(path, new FileAttributes.Builder().withUIDGID(uid, gid(path)).build()); }
public void setLength(long len) throws IOException { setAttributes(new FileAttributes.Builder().withSize(len).build()); }
@Override public void setUnixGroup(final Path file, final String group) throws BackgroundException { final FileAttributes attr = new FileAttributes.Builder() .withUIDGID(0, new Integer(group)) .build(); try { session.sftp().setAttributes(file.getAbsolute(), attr); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
public FileAttributes readFileAttributes() throws SFTPException { final FileAttributes.Builder builder = new FileAttributes.Builder(); try { final int mask = readUInt32AsInt(); if (FileAttributes.Flag.SIZE.isSet(mask)) builder.withSize(readUInt64()); if (FileAttributes.Flag.UIDGID.isSet(mask)) builder.withUIDGID(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.MODE.isSet(mask)) builder.withPermissions(readUInt32AsInt()); if (FileAttributes.Flag.ACMODTIME.isSet(mask)) builder.withAtimeMtime(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.EXTENDED.isSet(mask)) { final int extCount = readUInt32AsInt(); for (int i = 0; i < extCount; i++) builder.withExtended(readString(), readString()); } } catch (BufferException be) { throw new SFTPException(be); } return builder.build(); }
public void setLength(long len) throws IOException { setAttributes(new FileAttributes.Builder().withSize(len).build()); }
public void truncate(String path, long size) throws IOException { setattr(path, new FileAttributes.Builder().withSize(size).build()); }
public void chgrp(String path, int gid) throws IOException { setattr(path, new FileAttributes.Builder().withUIDGID(uid(path), gid).build()); }
public void chmod(String path, int perms) throws IOException { setattr(path, new FileAttributes.Builder().withPermissions(perms).build()); }
public void chown(String path, int uid) throws IOException { setattr(path, new FileAttributes.Builder().withUIDGID(uid, gid(path)).build()); }
private FileAttributes getAttributes(LocalSourceFile local) throws IOException { final FileAttributes.Builder builder = new FileAttributes.Builder().withPermissions(local.getPermissions()); if (local.providesAtimeMtime()) builder.withAtimeMtime(local.getLastAccessTime(), local.getLastModifiedTime()); return builder.build(); }