HADOOP-14431. ModifyTime of FileStatus returned by SFTPFileSystem's getFileStatus method is wrong. Contributed by Hongyuan Li.

This commit is contained in:
Brahma Reddy Battula 2017-06-06 12:31:40 +08:00
parent 6a28a2b914
commit 66c6fd8314
2 changed files with 10 additions and 1 deletions

View File

@ -277,7 +277,7 @@ private FileStatus getFileStatus(ChannelSftp channel, LsEntry sftpFile,
// Using default block size since there is no way in SFTP channel to know of // Using default block size since there is no way in SFTP channel to know of
// block sizes on server. The assumption could be less than ideal. // block sizes on server. The assumption could be less than ideal.
long blockSize = DEFAULT_BLOCK_SIZE; long blockSize = DEFAULT_BLOCK_SIZE;
long modTime = attr.getMTime() * 1000; // convert to milliseconds long modTime = attr.getMTime() * 1000L; // convert to milliseconds
long accessTime = attr.getATime() * 1000L; long accessTime = attr.getATime() * 1000L;
FsPermission permission = getPermissions(sftpFile); FsPermission permission = getPermissions(sftpFile);
// not be able to get the real user group name, just use the user and group // not be able to get the real user group name, just use the user and group

View File

@ -319,4 +319,13 @@ public void testGetAccessTime() throws IOException {
assertEquals(accessTime1, accessTime2); assertEquals(accessTime1, accessTime2);
} }
@Test
public void testGetModifyTime() throws IOException {
Path file = touch(localFs, name.getMethodName().toLowerCase() + "1");
java.io.File localFile = ((LocalFileSystem) localFs).pathToFile(file);
long modifyTime1 = localFile.lastModified();
long modifyTime2 = sftpFs.getFileStatus(file).getModificationTime();
assertEquals(modifyTime1, modifyTime2);
}
} }