HDFS-5033. Bad error message for fs -put/copyFromLocal if user doesn't have permissions to read the source (Darrell Taylor via aw)
This commit is contained in:
parent
d6e3164d4a
commit
bf500d9798
|
@ -446,6 +446,10 @@ public class FileUtil {
|
|||
IOUtils.closeStream( in );
|
||||
throw e;
|
||||
}
|
||||
} else if (!src.canRead()) {
|
||||
throw new IOException(src.toString() +
|
||||
": Permission denied");
|
||||
|
||||
} else {
|
||||
throw new IOException(src.toString() +
|
||||
": No such file or directory");
|
||||
|
|
|
@ -160,6 +160,9 @@ Trunk (Unreleased)
|
|||
|
||||
HDFS-6353. Check and make checkpoint before stopping the NameNode. (jing9)
|
||||
|
||||
HDFS-5033. Bad error message for fs -put/copyFromLocal if user
|
||||
doesn't have permissions to read the source (Darrell Taylor via aw)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -2317,6 +2317,77 @@ public class TestDFSShell {
|
|||
}
|
||||
}
|
||||
|
||||
/* [refs HDFS-5033]
|
||||
*
|
||||
* return a "Permission Denied" message instead of "No such file or Directory"
|
||||
* when trying to put/copyFromLocal a file that doesn't have read access
|
||||
*
|
||||
*/
|
||||
@Test (timeout = 30000)
|
||||
public void testCopyFromLocalWithPermissionDenied() throws Exception {
|
||||
Configuration conf = new Configuration();
|
||||
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
||||
.format(true).build();
|
||||
FsShell shell = null;
|
||||
FileSystem fs = null;
|
||||
PrintStream bak = null;
|
||||
|
||||
final File localFile = new File(TEST_ROOT_DIR, "testFileWithNoReadPermissions");
|
||||
final String localfilepath = new Path(localFile.getAbsolutePath()).toUri().toString();
|
||||
final String testdir = "/tmp/TestDFSShell-CopyFromLocalWithPermissionDenied-"
|
||||
+ counter.getAndIncrement();
|
||||
final Path hdfsTestDir = new Path(testdir);
|
||||
try {
|
||||
fs = cluster.getFileSystem();
|
||||
fs.mkdirs(hdfsTestDir);
|
||||
localFile.createNewFile();
|
||||
localFile.setReadable(false);
|
||||
writeFile(fs, new Path(testdir, "testFileForPut"));
|
||||
shell = new FsShell();
|
||||
|
||||
// capture system error messages, snarfed from testErrOutPut()
|
||||
bak = System.err;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PrintStream tmp = new PrintStream(out);
|
||||
System.setErr(tmp);
|
||||
|
||||
// Tests for put
|
||||
String[] argv = new String[] { "-put", localfilepath, testdir };
|
||||
int res = ToolRunner.run(shell, argv);
|
||||
assertEquals("put is working", ERROR, res);
|
||||
String returned = out.toString();
|
||||
assertTrue(" outputs Permission denied error message",
|
||||
(returned.lastIndexOf("Permission denied") != -1));
|
||||
|
||||
// Tests for copyFromLocal
|
||||
argv = new String[] { "-copyFromLocal", localfilepath, testdir };
|
||||
res = ToolRunner.run(shell, argv);
|
||||
assertEquals("copyFromLocal -f is working", ERROR, res);
|
||||
returned = out.toString();
|
||||
assertTrue(" outputs Permission denied error message",
|
||||
(returned.lastIndexOf("Permission denied") != -1));
|
||||
|
||||
} finally {
|
||||
if (bak != null) {
|
||||
System.setErr(bak);
|
||||
}
|
||||
|
||||
if (null != shell)
|
||||
shell.close();
|
||||
|
||||
if (localFile.exists())
|
||||
localFile.delete();
|
||||
|
||||
if (null != fs) {
|
||||
fs.delete(hdfsTestDir, true);
|
||||
fs.close();
|
||||
}
|
||||
cluster.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// setrep for file and directory.
|
||||
@Test (timeout = 30000)
|
||||
public void testSetrep() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue