HDFS-14807. SetTimes updates all negative values apart from -1. Contributed by Ayush Saxena.
This commit is contained in:
parent
0f549ec02a
commit
91b01a1db7
@ -1145,11 +1145,11 @@ void fsync(String src, long inodeId, String client, long lastBlockLength)
|
||||
* Sets the modification and access time of the file to the specified time.
|
||||
* @param src The string representation of the path
|
||||
* @param mtime The number of milliseconds since Jan 1, 1970.
|
||||
* Setting mtime to -1 means that modification time should not
|
||||
* Setting negative mtime means that modification time should not
|
||||
* be set by this call.
|
||||
* @param atime The number of milliseconds since Jan 1, 1970.
|
||||
* Setting atime to -1 means that access time should not be set
|
||||
* by this call.
|
||||
* Setting negative atime means that access time should not be
|
||||
* set by this call.
|
||||
*
|
||||
* @throws org.apache.hadoop.security.AccessControlException permission denied
|
||||
* @throws java.io.FileNotFoundException file <code>src</code> is not found
|
||||
|
@ -475,14 +475,14 @@ static boolean unprotectedSetTimes(
|
||||
boolean status = false;
|
||||
INode inode = iip.getLastINode();
|
||||
int latest = iip.getLatestSnapshotId();
|
||||
if (mtime != -1) {
|
||||
if (mtime >= 0) {
|
||||
inode = inode.setModificationTime(mtime, latest);
|
||||
status = true;
|
||||
}
|
||||
|
||||
// if the last access time update was within the last precision interval,
|
||||
// then no need to store access time
|
||||
if (atime != -1 && (status || force
|
||||
if (atime >= 0 && (status || force
|
||||
|| atime > inode.getAccessTime() + fsd.getAccessTimePrecision())) {
|
||||
inode.setAccessTime(atime, latest,
|
||||
fsd.getFSNamesystem().getSnapshotManager().
|
||||
|
@ -139,6 +139,13 @@ public void testTimes() throws IOException {
|
||||
" (" + mtime1 + ")");
|
||||
assertTrue(atime1 != 0);
|
||||
|
||||
// check setting negative value for atime and mtime.
|
||||
fileSys.setTimes(file1, -2, -2);
|
||||
// The values shouldn't change.
|
||||
stat = fileSys.getFileStatus(file1);
|
||||
assertEquals(mtime1, stat.getModificationTime());
|
||||
assertEquals(atime1, stat.getAccessTime());
|
||||
|
||||
//
|
||||
// record dir times
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user