Skip to content

Commit

Permalink
Attempt reading after success exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 8, 2024
1 parent 5d42918 commit 4098735
Showing 1 changed file with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2404,20 +2404,18 @@ public int getOwnerIdOf(File file) {
"%u",
file.getAbsolutePath()});
int attempts = this.attempts;
boolean exited = false;
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
line = reader.readLine();
} finally {
//reader.close();
}
String line = null;
do {
try {
if (process.exitValue() != 0) {
throw new IllegalStateException("Error while executing stat");
}
exited = true;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
line = reader.readLine();
} finally {
reader.close();
}
break;
} catch (IllegalThreadStateException ignored) {
try {
Expand All @@ -2428,7 +2426,7 @@ public int getOwnerIdOf(File file) {
}
}
} while (--attempts > 0);
if (!exited) {
if (line == null) {
process.destroy();
throw new IllegalStateException("Command for stat did not exit in time");
}
Expand Down Expand Up @@ -2484,23 +2482,23 @@ public int getOwnerIdOf(File file) {
try {
Process process = Runtime.getRuntime().exec(new String[]{"istat", file.getAbsolutePath()});
int attempts = this.attempts;
boolean exited = false;
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
} finally {
//reader.close();
}
String lines = null;
do {
try {
if (process.exitValue() != 0) {
throw new IllegalStateException("Error while executing istat");
}
exited = true;
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
} finally {
reader.close();
}
lines = output.toString();
break;
} catch (IllegalThreadStateException ignored) {
try {
Expand All @@ -2511,15 +2509,15 @@ public int getOwnerIdOf(File file) {
}
}
} while (--attempts > 0);
if (!exited) {
if (lines == null) {
process.destroy();
throw new IllegalStateException("Command for istat did not exit in time");
}
Matcher matcher = AIX_OWNER_PATTERN.matcher(output.toString());
Matcher matcher = AIX_OWNER_PATTERN.matcher(lines);
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
} else {
throw new IllegalStateException("Unable to parse response from istat command: " + output);
throw new IllegalStateException("Unable to parse response from istat command: " + lines);
}
} catch (IOException exception) {
throw new IllegalStateException("Unable to execute istat command", exception);
Expand Down Expand Up @@ -2572,20 +2570,18 @@ public int getOwnerIdOf(File file) {
"%u",
file.getAbsolutePath()});
int attempts = this.attempts;
boolean exited = false;
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
line = reader.readLine();
} finally {
//reader.close();
}
String line = null;
do {
try {
if (process.exitValue() != 0) {
throw new IllegalStateException("Error while executing stat");
}
exited = true;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
try {
line = reader.readLine();
} finally {
reader.close();
}
break;
} catch (IllegalThreadStateException ignored) {
try {
Expand All @@ -2596,7 +2592,7 @@ public int getOwnerIdOf(File file) {
}
}
} while (--attempts > 0);
if (!exited) {
if (line == null) {
process.destroy();
throw new IllegalStateException("Command for stat did not exit in time");
}
Expand Down

0 comments on commit 4098735

Please sign in to comment.