Skip to content

Commit

Permalink
Check contents of config file from home
Browse files Browse the repository at this point in the history
Don't try to use it if it doesn't contain valid JSON
  • Loading branch information
jemoreira committed Nov 6, 2024
1 parent 5456bb9 commit 381f461
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "common/libs/utils/contains.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/flag_parser.h"
#include "common/libs/utils/json.h"
#include "common/libs/utils/result.h"
#include "common/libs/utils/users.h"
#include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h"
Expand All @@ -50,6 +51,7 @@
#include "host/commands/cvd/utils/interrupt_listener.h"
#include "host/commands/cvd/utils/subprocess_waiter.h"
#include "host/libs/config/config_constants.h"
#include "host/libs/config/cuttlefish_config.h"

namespace cuttlefish {
namespace {
Expand Down Expand Up @@ -196,7 +198,8 @@ static Result<void> UpdateInstanceArgs(cvd_common::Args& args,
Result<void> SymlinkPreviousConfig(const std::string& group_home_dir) {
auto system_wide_home = CF_EXPECT(SystemWideUserHome());
auto config_from_home = system_wide_home + "/.cuttlefish_config.json";
if (!FileExists(config_from_home)) {
if (!FileExists(config_from_home) || !LoadFromFile(config_from_home).ok()) {
// Skip if the file doesn't exist or can't be parsed as JSON
return {};
}
auto link = group_home_dir + "/.cuttlefish_config.json";
Expand Down

0 comments on commit 381f461

Please sign in to comment.