abstractdog commented on code in PR #471:
URL: https://github.com/apache/tez/pull/471#discussion_r2999751103
##########
tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/CSVResult.java:
##########
@@ -93,31 +95,52 @@ public void setComments(String comments) {
'}';
}
- //For testing
- public void dumpToFile(String fileName) throws IOException {
- OutputStreamWriter writer = new OutputStreamWriter(
- new FileOutputStream(new File(fileName)),
- Charset.forName("UTF-8").newEncoder());
- BufferedWriter bw = new BufferedWriter(writer);
- bw.write(Joiner.on(",").join(headers));
- bw.newLine();
- for (String[] record : recordsList) {
-
- if (record.length != headers.length) {
- continue; //LOG error msg?
- }
+ private static File validateOutputFile(String fileName) throws IOException {
+ //null or empty string check
+ if (fileName == null || fileName.trim().isEmpty()) {
+ throw new IllegalArgumentException("fileName must not be null or empty");
+ }
+
+ // resolve relative path
+ File target = new File(fileName).getCanonicalFile();
+ File parent = target.getParentFile();
+
+ // check if the parent directory exists
+ if (parent == null || !parent.isDirectory()) {
+ throw new IOException("Parent directory does not exist: " + parent);
+ }
+ // check if the parent directory is writable
+ if (!parent.canWrite()) {
+ throw new IOException("No write permission on directory: " + parent);
+ }
+ return target;
Review Comment:
Should we check this separately? If the directory isn’t writable by the
user, the write will fail anyway, right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]