продолжение рефакторинга и проверка на занятость файлов

This commit is contained in:
2024-10-07 20:04:11 +03:00
parent e7f661f7ad
commit 7fac84740d
41 changed files with 164 additions and 184 deletions

View File

@@ -2,6 +2,7 @@ package TestingSystem.DVM;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import Common_old.Constants;
import Common_old.UI.UI;
import _VisualDVM.Global;
import Common_old.Utils.Utils;
import GlobalData.Machine.Machine;
@@ -194,6 +195,7 @@ public class UserConnection {
try {
sftpChannel.lstat(file_full_name);
return true;
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
// file doesn't exist
@@ -204,6 +206,24 @@ public class UserConnection {
}
}
}
public boolean Busy(String file_full_name) throws Exception {
try {
sftpChannel.lstat(file_full_name);
return true;
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_PERMISSION_DENIED) {
// file busy
return false;
} else {
// something else went wrong
throw e;
}
}
}
public boolean Busy(RemoteFile file) throws Exception {
return Busy(file.full_name);
}
public boolean Exists(RemoteFile file) throws Exception {
return Exists(file.full_name);
}
@@ -466,6 +486,12 @@ public class UserConnection {
Utils.sleep(1000);
}
}
public void waitForFileFree(RemoteFile file) throws Exception {
while (!Busy(file)) {
System.out.println(file.full_name + " PERMISSION DENIED");
Utils.sleep(1000);
}
}
public String startShellProcess(RemoteFile directory, String outFileName, String... commands) throws Exception {
Vector<String> commands_ = new Vector<>();
commands_.add("cd " + CommonUtils.DQuotes(directory.full_name));
@@ -488,6 +514,7 @@ public class UserConnection {
ShellConnect();
pin.write(("nohup " + start_command + " &\r\n").getBytes());
waitForFileCreation(outFile);
waitForFileFree(outFile);
ShellDisconnect();
return readFromFile(outFile).replace("\n", "").replace("\r", "");
}