Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ static FileStatus setTimes(
if (fsd.isPermissionEnabled()) {
fsd.checkPathAccess(pc, iip, FsAction.WRITE);
}
final INode inode = iip.getLastINode();
if (inode == null) {
throw new FileNotFoundException("File/Directory " + iip.getPath() +
" does not exist.");
}
boolean changed = unprotectedSetTimes(fsd, iip, mtime, atime, true);
if (changed) {
fsd.getEditLog().logTimes(iip.getPath(), mtime, atime);
Expand Down Expand Up @@ -305,7 +300,7 @@ static boolean unprotectedSetOwner(

static boolean setTimes(
FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force)
throws QuotaExceededException {
throws FileNotFoundException {
fsd.writeLock();
try {
return unprotectedSetTimes(fsd, iip, mtime, atime, force);
Expand Down Expand Up @@ -497,10 +492,14 @@ private static void setDirStoragePolicy(

static boolean unprotectedSetTimes(
FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force)
throws QuotaExceededException {
throws FileNotFoundException {
assert fsd.hasWriteLock();
boolean status = false;
INode inode = iip.getLastINode();
if (inode == null) {
throw new FileNotFoundException("File/Directory " + iip.getPath() +
" does not exist.");
}
int latest = iip.getLatestSnapshotId();
if (mtime >= 0) {
inode = inode.setModificationTime(mtime, latest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.FileNotFoundException;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
Expand All @@ -40,7 +41,8 @@ public class TestFSDirAttrOp {
LoggerFactory.getLogger(TestFSDirAttrOp.class);

private boolean unprotectedSetTimes(long atime, long atime0, long precision,
long mtime, boolean force) throws QuotaExceededException {
long mtime, boolean force)
throws FileNotFoundException {
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
SnapshotManager ssMgr = Mockito.mock(SnapshotManager.class);
FSDirectory fsd = Mockito.mock(FSDirectory.class);
Expand Down Expand Up @@ -131,4 +133,16 @@ public void testUnprotectedSetTimes() throws Exception {
assertTrue("SetTimes should update access time",
unprotectedSetTimes(100, 0, 1000, 1, false));
}

@Test(expected = FileNotFoundException.class)
public void testUnprotectedSetTimesFNFE()
throws FileNotFoundException {
FSDirectory fsd = Mockito.mock(FSDirectory.class);
INodesInPath iip = Mockito.mock(INodesInPath.class);

when(fsd.hasWriteLock()).thenReturn(Boolean.TRUE);
when(iip.getLastINode()).thenReturn(null);

FSDirAttrOp.unprotectedSetTimes(fsd, iip, 0, 0, false);
}
}