mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:45:37 +02:00
Improve cdc_fuse_fs and path (#2)
Improve cdc_fuse_fs and path Improves the error handling in path so that std:error_codes are not assumed to be of system category, and also that their messages are displayed. Also improves debug messages in GameletComponent.
This commit is contained in:
@@ -36,19 +36,36 @@ namespace {
|
||||
constexpr char kFuseFilename[] = "cdc_fuse_fs";
|
||||
constexpr char kLibFuseFilename[] = "libfuse.so";
|
||||
|
||||
absl::StatusOr<bool> IsUpToDate(const std::string& components_arg) {
|
||||
bool IsUpToDate(const std::string& components_arg) {
|
||||
// Components are expected to reside in the same dir as the executable.
|
||||
std::string component_dir;
|
||||
RETURN_IF_ERROR(path::GetExeDir(&component_dir));
|
||||
absl::Status status = path::GetExeDir(&component_dir);
|
||||
if (!status.ok()) {
|
||||
// Should(TM) be super rare, so just log an error.
|
||||
LOG_DEBUG("Failed to exe dir: %s", status.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<GameletComponent> components =
|
||||
GameletComponent::FromCommandLineArgs(components_arg);
|
||||
if (components.size() == 0) {
|
||||
LOG_DEBUG("Invalid components arg '%s'", components_arg);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<GameletComponent> our_components;
|
||||
absl::Status status =
|
||||
GameletComponent::Get({path::Join(component_dir, kFuseFilename),
|
||||
path::Join(component_dir, kLibFuseFilename)},
|
||||
&our_components);
|
||||
if (!status.ok() || components != our_components) {
|
||||
status = GameletComponent::Get({path::Join(component_dir, kFuseFilename),
|
||||
path::Join(component_dir, kLibFuseFilename)},
|
||||
&our_components);
|
||||
if (!status.ok()) {
|
||||
LOG_DEBUG("Failed to get component data: %s", status.ToString())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (components != our_components) {
|
||||
LOG_DEBUG("Component mismatch, args don't match ours '%s' != '%s'",
|
||||
GameletComponent::ToCommandLineArgs(components),
|
||||
GameletComponent::ToCommandLineArgs(our_components));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,13 +129,7 @@ int main(int argc, char* argv[]) {
|
||||
cdc_ft::Log::VerbosityToLogLevel(verbosity)));
|
||||
|
||||
// Perform up-to-date check.
|
||||
absl::StatusOr<bool> is_up_to_date = cdc_ft::IsUpToDate(components);
|
||||
if (!is_up_to_date.ok()) {
|
||||
LOG_ERROR("Failed to check file system freshness: %s",
|
||||
is_up_to_date.status().ToString());
|
||||
return static_cast<int>(is_up_to_date.status().code());
|
||||
}
|
||||
if (!*is_up_to_date) {
|
||||
if (!cdc_ft::IsUpToDate(components)) {
|
||||
printf("%s\n", cdc_ft::kFuseNotUpToDate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user