5454#include " cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h"
5555#include " cuttlefish/host/commands/assemble_cvd/flags_defaults.h"
5656#include " cuttlefish/host/commands/assemble_cvd/instance_image_files.h"
57+ #include " cuttlefish/host/commands/assemble_cvd/required_directories.h"
5758#include " cuttlefish/host/commands/assemble_cvd/resolve_instance_files.h"
5859#include " cuttlefish/host/commands/assemble_cvd/touchpad.h"
5960#include " cuttlefish/host/libs/command_util/snapshot_utils.h"
6263#include " cuttlefish/host/libs/config/custom_actions.h"
6364#include " cuttlefish/host/libs/config/defaults/defaults.h"
6465#include " cuttlefish/host/libs/config/fastboot/fastboot.h"
65- #include " cuttlefish/host/libs/config/fetcher_config.h"
6666#include " cuttlefish/host/libs/config/fetcher_configs.h"
6767#include " cuttlefish/host/libs/feature/inject.h"
6868#include " cuttlefish/posix/symlink.h"
@@ -399,18 +399,13 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
399399 CF_EXPECT (CleanPriorFiles (preserving, clean_dirs),
400400 " Failed to clean prior files" );
401401
402- auto default_group = " cvdnetwork" ;
402+ std::string default_group = " cvdnetwork" ;
403403 const mode_t default_mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
404404
405- CF_EXPECT (EnsureDirectoryExists (config.root_dir ()));
406- CF_EXPECT (EnsureDirectoryExists (config.assembly_dir ()));
407- CF_EXPECT (EnsureDirectoryExists (config.instances_dir ()));
408- CF_EXPECT (EnsureDirectoryExists (config.instances_uds_dir (), default_mode,
409- default_group));
410- CF_EXPECT (EnsureDirectoryExists (config.environments_dir (), default_mode,
411- default_group));
412- CF_EXPECT (EnsureDirectoryExists (config.environments_uds_dir (), default_mode,
413- default_group));
405+ for (const std::string& dir : RequiredDirectories (config)) {
406+ CF_EXPECT (EnsureDirectoryExists (dir, default_mode, default_group));
407+ }
408+
414409 if (!snapshot_path.empty ()) {
415410 SharedFD temp = SharedFD::Creat (config.AssemblyPath (" restore" ), 0660 );
416411 if (!temp->IsOpen ()) {
@@ -420,41 +415,9 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
420415
421416 auto environment =
422417 const_cast <const CuttlefishConfig&>(config).ForDefaultEnvironment ();
423-
424- CF_EXPECT (EnsureDirectoryExists (environment.environment_dir (), default_mode,
425- default_group));
426- CF_EXPECT (EnsureDirectoryExists (environment.environment_uds_dir (),
427- default_mode, default_group));
428- CF_EXPECT (EnsureDirectoryExists (environment.PerEnvironmentLogPath (" " ),
429- default_mode, default_group));
430- CF_EXPECT (
431- EnsureDirectoryExists (environment.PerEnvironmentGrpcSocketPath (" " ),
432- default_mode, default_group));
433-
434418 LOG (INFO) << " Path for instance UDS: " << config.instances_uds_dir ();
435419
436- if (log->LinkAtCwd (config.AssemblyPath (" assemble_cvd.log" ))) {
437- LOG (ERROR) << " Unable to persist assemble_cvd log at "
438- << config.AssemblyPath (" assemble_cvd.log" )
439- << " : " << log->StrError ();
440- }
441420 for (const auto & instance : config.Instances ()) {
442- // Create instance directory if it doesn't exist.
443- CF_EXPECT (EnsureDirectoryExists (instance.instance_dir ()));
444- auto internal_dir = instance.instance_dir () + " /" + kInternalDirName ;
445- CF_EXPECT (EnsureDirectoryExists (internal_dir));
446- auto shared_dir = instance.instance_dir () + " /" + kSharedDirName ;
447- CF_EXPECT (EnsureDirectoryExists (shared_dir));
448- auto recording_dir = instance.instance_dir () + " /recording" ;
449- CF_EXPECT (EnsureDirectoryExists (recording_dir));
450- CF_EXPECT (EnsureDirectoryExists (instance.PerInstanceLogPath (" " )));
451-
452- CF_EXPECT (EnsureDirectoryExists (instance.instance_uds_dir (), default_mode,
453- default_group));
454- CF_EXPECT (EnsureDirectoryExists (instance.instance_internal_uds_dir (),
455- default_mode, default_group));
456- CF_EXPECT (EnsureDirectoryExists (instance.PerInstanceGrpcSocketPath (" " ),
457- default_mode, default_group));
458421 std::string vsock_dir = fmt::format (" {}/vsock_{}_{}" , TempDir (),
459422 instance.vsock_guest_cid (), getuid ());
460423 if (DirectoryExists (vsock_dir, /* follow_symlinks */ false ) &&
@@ -466,6 +429,13 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
466429 // TODO(schuffelen): Move this code somewhere better
467430 CF_EXPECT (CreateLegacySymlinks (instance, environment));
468431 }
432+
433+ if (log->LinkAtCwd (config.AssemblyPath (" assemble_cvd.log" ))) {
434+ LOG (ERROR) << " Unable to persist assemble_cvd log at "
435+ << config.AssemblyPath (" assemble_cvd.log" ) << " : "
436+ << log->StrError ();
437+ }
438+
469439 CF_EXPECT (SaveConfig (config), " Failed to initialize configuration" );
470440 }
471441
0 commit comments