Skip to content

Commit

Permalink
[improve][plugin][hdfswriter] add check for writable permissions on H…
Browse files Browse the repository at this point in the history
…DFS path before writing

This commit introduces a check to verify if a specified HDFS path has writable permissions before
attempting to write data. This ensures that write operations do not fail due to insufficient permissions,
improving the robustness of the file handling process.
  • Loading branch information
wgzhao committed Sep 12, 2024
1 parent d2121e7 commit 56b0414
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,16 @@ public Class<? extends CompressionCodec> getCompressCodec(String compress)
}
return codecClass;
}

public boolean isPathWritable(String path) {
try {
Path p = new Path(path);
Path tempFile = new Path(p, "._write_test_" + System.currentTimeMillis());
fileSystem.create(tempFile, true).close();
fileSystem.delete(tempFile, false);
return true;
} catch (IOException | IllegalArgumentException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ else if ("nonConflict".equals(writeMode) && isExistFile) {
throw AddaxException.asAddaxException(HdfsWriterErrorCode.ILLEGAL_VALUE,
String.format("The directory [%s] does not exists. please create it first. ", path));
}

// validate the write permission
if (!hdfsHelper.isPathWritable(path)) {
throw AddaxException.asAddaxException(HdfsWriterErrorCode.ILLEGAL_VALUE,
String.format("The path [%s] is not writable or permission denied", path));
}
}

@Override
Expand Down

0 comments on commit 56b0414

Please sign in to comment.