Skip to content

Commit 90adea7

Browse files
committed
add test for not exist file
1 parent 3347721 commit 90adea7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/Warehouse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ public boolean isWritable(Path path) {
512512
return false;
513513
}
514514
try {
515-
HdfsUtils.checkFileAccess(path, conf, FsAction.WRITE);
515+
FileSystem fs = getFs(path);
516+
HdfsUtils.checkFileAccess(fs, path, FsAction.WRITE);
516517
return true;
517518
} catch (FileNotFoundException fnfe){
518519
// File named by path doesn't exist; nothing to validate.

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ public class HdfsUtils {
6363

6464
/**
6565
* Check the permissions on a file.
66+
* @param fs Filesystem the file is contained in
6667
* @param path the file path
67-
* @param conf the {@link Configuration} used when checking permissions
6868
* @param action action to be performed
6969
* @throws IOException If thrown by Hadoop
7070
*/
71-
public static void checkFileAccess(Path path, Configuration conf, FsAction action)
71+
public static void checkFileAccess(FileSystem fs, Path path, FsAction action)
7272
throws IOException {
73-
FileSystem fs = path.getFileSystem(conf);
7473
checkFileAccess(fs, path, action, SecurityUtils.getUGI());
7574
}
7675

standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestHdfsUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.Test;
3434
import org.junit.experimental.categories.Category;
3535

36+
import java.io.FileNotFoundException;
3637
import java.io.IOException;
3738
import java.util.ArrayList;
3839
import java.util.List;
@@ -174,6 +175,13 @@ public void otherNoExecute() throws IOException {
174175
HdfsUtils.checkFileAccess(fs, p, FsAction.EXECUTE, ugi);
175176
}
176177

178+
@Test (expected = FileNotFoundException.class)
179+
public void nonExistentFile() throws IOException {
180+
FileSystem fs = FileSystem.get(new Configuration());
181+
Path p = new Path("/tmp/nosuchfile");
182+
UserGroupInformation ugi = SecurityUtils.getUGI();
183+
HdfsUtils.checkFileAccess(fs, p, FsAction.READ, ugi);
184+
}
177185

178186
@Test(expected = AccessControlException.class)
179187
public void accessPerssionFromCustomFilesystem() throws IOException {

0 commit comments

Comments
 (0)