Оптимизация команды Exists для SSH
This commit is contained in:
@@ -59,11 +59,12 @@ public class InstallServerSapfor extends ConnectionPass<Object> {
|
||||
ShowMessage1("Сборка SAPFOR...");
|
||||
//-
|
||||
RemoteFile repo_bin = new RemoteFile(repoSapforHome.full_name, "Sapfor_F");
|
||||
if (Exists(repoSapforHome.full_name, repo_bin.name))
|
||||
if (Exists(repo_bin))
|
||||
sftpChannel.rm(repo_bin.full_name);
|
||||
//--
|
||||
performScript(repoSapforHome, "cmake ../", "make -j 4");
|
||||
result = Exists(repoSapforHome.full_name, "Sapfor_F");
|
||||
RemoteFile repoSapfor = new RemoteFile(repoSapforHome, "Sapfor_F");
|
||||
result = Exists(repoSapfor);
|
||||
if (result) {
|
||||
RemoteFile sapforsDirectory = new RemoteFile(testingSystemHome.full_name, "Sapfors", true);
|
||||
//создать папку. Для того чтобы скопировать из репозитория.
|
||||
@@ -116,6 +117,5 @@ public class InstallServerSapfor extends ConnectionPass<Object> {
|
||||
protected void performDone() throws Exception {
|
||||
passes.get(PassCode_2021.PublishServerSapfor).Do(serverSapfor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RemoteInitialiseUser extends CurrentConnectionPass<String> {
|
||||
"cd " + Utils.DQuotes(sftpChannel.pwd()), //нужны ли тут кавычки?
|
||||
"g++ " + starter_code + " -o " + starter,
|
||||
"g++ " + launcher_code + " -o " + launcher,
|
||||
"g++ -O3 -std=c++17 Planner.cpp -o " + planner,
|
||||
"g++ -O3 -std=C++17 Planner.cpp -o " + planner,
|
||||
"chmod 0777 " + starter,
|
||||
"chmod 0777 " + launcher,
|
||||
"chmod 0777 " + planner
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
isConnected = true; // теперь можно прерывать метод.
|
||||
if (needsInitialize()) {
|
||||
RemoteFile userWorkspace = new RemoteFile(user.workspace, true);
|
||||
if (!Exists(sftpChannel.getHome(), userWorkspace.name))
|
||||
if (!Exists(userWorkspace))
|
||||
throw new WorkspaceNotFoundException(
|
||||
"Рабочее пространство пользователя " + Utils.Brackets(user.login)
|
||||
+ " на машине " + Utils.Brackets(machine.getURL())
|
||||
@@ -171,8 +171,8 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
sftpChannel.get(src, dst);
|
||||
}
|
||||
//с проверкой.
|
||||
public boolean tryGetSingleFile(RemoteFile src, File dst, int maxSize) throws Exception {
|
||||
if (Exists(src.parent, src.name)) {
|
||||
public boolean tryGetSingleFileWithMaxSize(RemoteFile src, File dst, int maxSize) throws Exception {
|
||||
if (Exists(src)) {
|
||||
if ((maxSize == 0) || (getFileKBSize(src.full_name) <= maxSize)) {
|
||||
getSingleFile(src.full_name, dst.getAbsolutePath());
|
||||
return true;
|
||||
@@ -186,19 +186,11 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
sftpChannel.put(src.getAbsolutePath(), dst.full_name);
|
||||
}
|
||||
public void tryMKDir(RemoteFile dir) throws Exception {
|
||||
// System.out.print("try mkdir: '" + dir.full_name);
|
||||
if (!Exists(dir.parent, dir.name)) sftpChannel.mkdir(dir.full_name);
|
||||
// System.out.println("..done");
|
||||
if (!Exists(dir)) sftpChannel.mkdir(dir.full_name);
|
||||
}
|
||||
public void tryRM(RemoteFile file) throws Exception {
|
||||
// System.out.print("try remove: '" + file.full_name);
|
||||
if (Exists(file.parent, file.name)) {
|
||||
// System.out.print("' :exists.needs remove..");
|
||||
if (Exists(file))
|
||||
sftpChannel.rm(file.full_name);
|
||||
// System.out.println(" +");
|
||||
} else {
|
||||
// System.out.println("no such file");
|
||||
}
|
||||
}
|
||||
public void putSingleFile(String src, String dst) throws Exception {
|
||||
sftpChannel.put(src, dst);
|
||||
@@ -213,16 +205,6 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
}
|
||||
protected void ServerAction() throws Exception {
|
||||
}
|
||||
//тут имя файла короткое.
|
||||
public boolean Exists(String folder, String name) throws Exception {
|
||||
Vector<ChannelSftp.LsEntry> files = sftpChannel.ls(folder);
|
||||
for (ChannelSftp.LsEntry file : files) {
|
||||
if (file.getFilename().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//https://losst.ru/komanda-find-v-linux#%D0%9E%D1%81%D0%BD%D0%BE%D0%B2%D0%BD%D1%8B%D0%B5_%D0%BF%D0%B0%D1%80%D0%B0%D0%BC%D0%B5%D1%82%D1%80%D1%8B_%D0%BA%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D1%8B_find
|
||||
public String getStarter() {
|
||||
return String.join("/", user.workspace, modules, starter);
|
||||
@@ -385,7 +367,7 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
//скорее всего,временные методы. они есть в UserConnection, при удаленном запуске тестирования
|
||||
//--------------------------------------------------------------------------------
|
||||
public void MKDIR(RemoteFile dir) throws Exception {
|
||||
if (!Exists(dir.parent, dir.name)) sftpChannel.mkdir(dir.full_name);
|
||||
if (!Exists(dir)) sftpChannel.mkdir(dir.full_name);
|
||||
}
|
||||
//--
|
||||
public Pair<RemoteFile, RemoteFile> performScript(RemoteFile directory, String... commands) throws Exception {
|
||||
@@ -398,7 +380,7 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
files.add(out);
|
||||
files.add(err);
|
||||
for (RemoteFile file : files) {
|
||||
if (Exists(directory.full_name, file.name))
|
||||
if (Exists(directory))
|
||||
sftpChannel.rm(file.full_name);
|
||||
}
|
||||
//--
|
||||
@@ -406,9 +388,27 @@ public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
//--
|
||||
ShellCommand("cd " + Utils.DQuotes(directory.full_name),
|
||||
script_file.full_name + " 1>" + Constants.out_file + " 2>" + Constants.err_file);
|
||||
|
||||
return new Pair<>(out, err);
|
||||
}
|
||||
//--
|
||||
//--
|
||||
public boolean Exists(String file_full_name) throws Exception {
|
||||
try {
|
||||
sftpChannel.stat(file_full_name);
|
||||
return true;
|
||||
} catch (SftpException e) {
|
||||
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
|
||||
// file doesn't exist
|
||||
return false;
|
||||
} else {
|
||||
// something else went wrong
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean Exists(RemoteFile file) throws Exception {
|
||||
return Exists(file.full_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user