Module: Rakit::File
- Defined in:
- lib/rakit/file.rb,
lib/generated/rakit.file_pb.rb
Overview
Protobuf-first file operations (list directory, copy file). See specs/005-file-ops/contracts/ruby-api.md.
Constant Summary collapse
- FileConfig =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.FileConfig").msgclass
- ListRequest =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.ListRequest").msgclass
- FileEntry =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.FileEntry").msgclass
- ListResult =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.ListResult").msgclass
- CopyRequest =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.CopyRequest").msgclass
- CopyResult =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.file.CopyResult").msgclass
Class Method Summary collapse
Class Method Details
.copy(request) ⇒ Rakit::File::CopyResult
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rakit/file.rb', line 41 def copy(request) config = request.config || FileConfig.new src = normalize_path(request.source.to_s) dest_raw = normalize_path(request.destination.to_s) if src.nil? || dest_raw.nil? return error_copy_result(request.source.to_s, request.destination.to_s, "Empty or invalid path", 1) end unless ::File.exist?(src) return error_copy_result(src, dest_raw, "Source does not exist: #{src}", 1) end if ::File.directory?(src) return error_copy_result(src, dest_raw, "Source is a directory (MVP: file only)", 1) end dest_path = resolve_copy_destination(src, dest_raw) parent = ::File.dirname(dest_path) unless ::File.directory?(parent) if config.create_directories FileUtils.mkdir_p(parent) else return error_copy_result(src, dest_path, "Parent directory does not exist: #{parent}", 1) end end if ::File.file?(dest_path) && !config.overwrite return error_copy_result(src, dest_path, "Destination file exists (use overwrite to replace)", 1) end bytes = perform_copy(src, dest_path, config) CopyResult.new( success: true, message: "", source: src, destination: dest_path, exit_code: 0, stderr: "", bytes_copied: bytes || 0 ) rescue => e error_copy_result(request.source.to_s, request.destination.to_s, e., 1) end |
.list(request) ⇒ Rakit::File::ListResult
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rakit/file.rb', line 12 def list(request) dir_path = normalize_path(request.directory.to_s) if dir_path.nil? return error_list_result("Empty or invalid directory path", 1) end unless ::File.exist?(dir_path) return error_list_result("Directory does not exist: #{dir_path}", 1) end unless ::File.directory?(dir_path) return error_list_result("Not a directory: #{dir_path}", 1) end include_hidden = request.include_hidden follow_symlinks = request.config&.follow_symlinks == true entries = request.recursive ? list_entries_recursive(dir_path, include_hidden, follow_symlinks) : list_entries_one_dir(dir_path, include_hidden, follow_symlinks) ListResult.new( success: true, message: "", entries: entries, exit_code: 0, stderr: "" ) rescue => e error_list_result("#{e.}", 1) end |