mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
bugfix related to setting attributes on sftp upload
This commit is contained in:
@@ -25,6 +25,8 @@ import java.util.Set;
|
||||
|
||||
public final class FileAttributes {
|
||||
|
||||
public static final FileAttributes EMPTY = new FileAttributes();
|
||||
|
||||
public static enum Flag {
|
||||
|
||||
SIZE(0x00000001),
|
||||
@@ -58,7 +60,7 @@ public final class FileAttributes {
|
||||
private final long mtime;
|
||||
private final Map<String, String> ext = new HashMap<String, String>();
|
||||
|
||||
public FileAttributes() {
|
||||
private FileAttributes() {
|
||||
size = atime = mtime = uid = gid = mask = 0;
|
||||
mode = new FileMode(0);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SFTPClient {
|
||||
|
||||
public RemoteFile open(String filename, Set<OpenMode> mode)
|
||||
throws IOException {
|
||||
return open(filename, mode, new FileAttributes());
|
||||
return open(filename, mode, FileAttributes.EMPTY);
|
||||
}
|
||||
|
||||
public RemoteFile open(String filename)
|
||||
|
||||
@@ -122,7 +122,7 @@ public class SFTPEngine
|
||||
|
||||
public RemoteFile open(String filename, Set<OpenMode> modes)
|
||||
throws IOException {
|
||||
return open(filename, modes, new FileAttributes());
|
||||
return open(filename, modes, FileAttributes.EMPTY);
|
||||
}
|
||||
|
||||
public RemoteFile open(String filename)
|
||||
@@ -155,14 +155,12 @@ public class SFTPEngine
|
||||
|
||||
public void makeDir(String path, FileAttributes attrs)
|
||||
throws IOException {
|
||||
doRequest(
|
||||
newRequest(PacketType.MKDIR).putString(path).putFileAttributes(attrs)
|
||||
).ensureStatusPacketIsOK();
|
||||
doRequest(newRequest(PacketType.MKDIR).putString(path).putFileAttributes(attrs)).ensureStatusPacketIsOK();
|
||||
}
|
||||
|
||||
public void makeDir(String path)
|
||||
throws IOException {
|
||||
makeDir(path, new FileAttributes());
|
||||
makeDir(path, FileAttributes.EMPTY);
|
||||
}
|
||||
|
||||
public void symlink(String linkpath, String targetpath)
|
||||
|
||||
@@ -109,7 +109,7 @@ public class SFTPFileTransfer
|
||||
private void downloadDir(final RemoteResourceInfo remote, final File local)
|
||||
throws IOException {
|
||||
final File adjusted = FileTransferUtil.getTargetDirectory(local, remote.getName());
|
||||
setAttributes(remote, adjusted);
|
||||
copyAttributes(remote, adjusted);
|
||||
final RemoteDirectory rd = sftp.openDir(remote.getPath());
|
||||
try {
|
||||
for (RemoteResourceInfo rri : rd.scan(getDownloadFilter()))
|
||||
@@ -122,7 +122,7 @@ public class SFTPFileTransfer
|
||||
private void downloadFile(final RemoteResourceInfo remote, final File local)
|
||||
throws IOException {
|
||||
final File adjusted = FileTransferUtil.getTargetFile(local, remote.getName());
|
||||
setAttributes(remote, adjusted);
|
||||
copyAttributes(remote, adjusted);
|
||||
final RemoteFile rf = sftp.open(remote.getPath());
|
||||
try {
|
||||
final FileOutputStream fos = new FileOutputStream(adjusted);
|
||||
@@ -137,7 +137,7 @@ public class SFTPFileTransfer
|
||||
}
|
||||
}
|
||||
|
||||
private void setAttributes(final RemoteResourceInfo remote, final File local)
|
||||
private void copyAttributes(final RemoteResourceInfo remote, final File local)
|
||||
throws IOException {
|
||||
final FileAttributes attrs = remote.getAttributes();
|
||||
getModeSetter().setPermissions(local, attrs.getMode().getPermissionsMask());
|
||||
@@ -172,8 +172,10 @@ public class SFTPFileTransfer
|
||||
private void uploadFile(File local, String remote)
|
||||
throws IOException {
|
||||
final String adjusted = prepareFile(local, remote);
|
||||
final RemoteFile rf = sftp.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC),
|
||||
getAttributes(local));
|
||||
final RemoteFile rf = sftp.open(adjusted, EnumSet.of(OpenMode.WRITE,
|
||||
OpenMode.CREAT,
|
||||
OpenMode.TRUNC));
|
||||
rf.setAttributes(getAttributes(local));
|
||||
try {
|
||||
final FileInputStream fis = new FileInputStream(local);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user