Files
netris-cdc-file-transfer/cdc_rsync/server_arch.h
Lutz Justen a8b948b323 [cdc_rsync] Add initial support for Windows (#51)
Adds a ServerArch class whose job it is to encapsulate differences
between Windows and Linux cdc_rsync_servers. It detects the type
based on a heuristic in the destination path. This is not fool proof
and will probably require further work, like falling back to the other
type if the detected one doesn't work.

Uses the ServerArch class to determine the different commands to start
the server and to deploy the server.

Note that the functionality is not well tested on Windows yet, but
copying plain files works.
2023-01-17 13:34:14 +01:00

77 lines
2.7 KiB
C++

/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CDC_RSYNC_SERVER_ARCH_H_
#define CDC_RSYNC_SERVER_ARCH_H_
#include <string>
namespace cdc_ft {
// Abstracts all architecture specifics of cdc_rsync_server deployment.
class ServerArch {
public:
enum class Type {
kLinux = 0,
kWindows = 1,
};
enum class UseCase { kSsh = 0, kScp = 1 };
// Detects the architecture type based on the destination path, e.g. path
// starting with C: indicate Windows.
static Type Detect(const std::string& destination);
ServerArch(Type type);
~ServerArch();
// Returns the arch-specific filename of cdc_rsync_server[.exe].
std::string CdcServerFilename() const;
// Returns the arch-specific directory where cdc_rsync_server is deployed.
// On Windows, |use_case| determines what type of env variables to use:
// - kSsh uses $env:appdata and works for ssh commands.
// - kScp uses AppData\\Roaming and works for scp commands.
// On Linux, this flag is ignored.
std::string RemoteToolsBinDir(UseCase use_case) const;
// Returns an arch-specific SSH shell command that gets invoked in order to
// start cdc_rsync_server. The command
// - creates RemoteToolsBinDir() if it does not exist (so that the server can
// be deployed there subsequently; scp can't create directories),
// - returns |exit_code_not_found| if cdc_rsync_server does not exist (to
// prevent the confusing bash output message
// "bash: .../cdc_rsync_server: No such file or directory"), and
// - runs the server with the provided |args|.
std::string GetStartServerCommand(int exit_code_not_found,
const std::string& args) const;
// Returns an arch-specific SSH shell command that gets invoked after
// cdc_rsync_server has been copied to a temp location. The command
// - makes the old cdc_rsync_server writable (if it exists),
// - makes the new cdc_rsync_server executable (Linux only) and
// - replaces the old cdc_rsync_server by the new one.
std::string GetDeployReplaceCommand(const std::string& old_server_path,
const std::string& new_server_path) const;
private:
Type type_;
};
} // namespace cdc_ft
#endif // CDC_RSYNC_SERVER_ARCH_H_