Skip to content

HADOOP-19599. Fix file permission errors as per the platform #7767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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 @@ -205,15 +205,31 @@ public ChecksumFSInputChecker(ChecksumFileSystem fs, Path file, int bufferSize)
} catch (IOException e) {
// mincing the message is terrible, but java throws permission
// exceptions as FNF because that's all the method signatures allow!
if (!(e instanceof FileNotFoundException) ||
e.getMessage().endsWith(" (Permission denied)")) {
if (!(e instanceof FileNotFoundException) || isPermissionDenied(e)) {
LOG.warn("Problem opening checksum file: "+ file +
". Ignoring exception: " , e);
}
set(fs.verifyChecksum, null, 1, 0);
}
}

/**
* Check if the exception is a permission denied error.
* This is used to differentiate between a missing checksum file
* and a permission denied error when trying to read it.
*
* @param e the IOException to check
* @return true if the exception indicates a permission denied error
*/
private static boolean isPermissionDenied(IOException e) {
String errorMessage = e.getMessage();
if (Path.WINDOWS) {
return errorMessage.endsWith(" (Access is denied)");
}

return errorMessage.endsWith(" (Permission denied)");
}

private long getChecksumFilePos( long dataPos ) {
return HEADER_LENGTH + FSInputChecker.CHECKSUM_SIZE*(dataPos/bytesPerSum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,29 @@ public void testPutSrcFileNoPerm()
System.setErr(new PrintStream(err));
shellRun(1, "-put", src.toString(), dst.toString());
System.setErr(oldErr);
System.err.print(err.toString());
assertTrue(err.toString().contains("(Permission denied)"));
System.err.print(err);
assertPermissionDenied(err);
} finally {
// make sure the test file can be deleted
lfs.setPermission(src, new FsPermission((short)0755));
}
}

/**
* Assert that the error message contains the expected permission denied
* message, which varies by platform.
*
* @param err the ByteArrayOutputStream containing the error output
*/
private static void assertPermissionDenied(ByteArrayOutputStream err) {
String errorMessage = err.toString();
if (Path.WINDOWS) {
assertTrue(errorMessage.contains("(Access is denied)"));
} else {
assertTrue(errorMessage.contains("(Permission denied)"));
}
}

@Test
public void testLazyPersistDirectOverwrite() throws Exception {
Path testRoot = new Path(testRootDir, "testLazyPersistDirectOverwrite");
Expand Down