Module: Aidp::SafeDirectory
- Included in:
- AutoUpdate::CheckpointStore, AutoUpdate::FailureTracker, AutoUpdate::UpdateLogger, Harness::State::Persistence, Harness::StateManager, Jobs::BackgroundRunner
- Defined in:
- lib/aidp/safe_directory.rb
Overview
Provides safe directory creation with automatic fallback for permission errors Used across AIDP components to handle CI environments and restricted filesystems
Instance Method Summary collapse
-
#safe_mkdir_p(path, component_name: "AIDP", skip_creation: false) ⇒ String
Safely create a directory with fallback to temp/home on permission errors.
Instance Method Details
#safe_mkdir_p(path, component_name: "AIDP", skip_creation: false) ⇒ String
Safely create a directory with fallback to temp/home on permission errors
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aidp/safe_directory.rb', line 16 def safe_mkdir_p(path, component_name: "AIDP", skip_creation: false) return path if skip_creation return path if Dir.exist?(path) begin FileUtils.mkdir_p(path) path rescue SystemCallError => e fallback = determine_fallback_path(path) # Suppress permission warnings during tests to reduce noise unless ENV["RSPEC_RUNNING"] == "true" Kernel.warn "[#{component_name}] Cannot create directory #{path}: #{e.class}: #{e.}" Kernel.warn "[#{component_name}] Using fallback directory: #{fallback}" end # Try to create fallback directory begin FileUtils.mkdir_p(fallback) unless Dir.exist?(fallback) rescue SystemCallError => e2 # Suppress fallback errors during tests too unless ENV["RSPEC_RUNNING"] == "true" Kernel.warn "[#{component_name}] Fallback directory creation also failed: #{e2.class}: #{e2.}" end end fallback end end |