Class: Pikuri::Tool::Workspace::Cwd
- Inherits:
-
Pikuri::Tool::Workspace
- Object
- Pikuri::Tool::Workspace
- Pikuri::Tool::Workspace::Cwd
- Defined in:
- lib/pikuri/tool/workspace.rb
Overview
Locks read+write to a single subtree (the root: passed at construction, with symlinks resolved). cwd equals the root.
Containment algorithm
#resolve walks up the input path to its deepest existing ancestor, realpath‘s that ancestor (resolving any symlinks in the existing portion), then verifies the resolved anchor is @root or a descendant. Four cases the algorithm must handle:
-
lib/foo.rb(exists) →existing= full path,anchorin root → returns the realpath’d file. -
lib/new/dir/foo.rb(intermediates missing) → walks up to @root/lib,anchorin root → returns the intended new path (caller mkdir_ps the parent before writing). -
lib/../../etc/passwd(..escape) →cleanpathcollapses..syntactically, walks land outside @root →Error. -
link/foo.rbwhere link → /etc (symlink escape) → walks tolink(which exists),realpathresolves through the symlink to/etc, outside @root →Error.
Pure lexical normalization (cleanpath + prefix check) catches cases 1–3 but misses case 4. The walk-up step adds the realpath pass on the existing prefix, closing that gap.
Instance Method Summary collapse
- #cwd ⇒ Pathname
-
#initialize(root:) ⇒ Cwd
constructor
A new instance of Cwd.
- #resolve_for_read(path) ⇒ Pathname
- #resolve_for_write(path) ⇒ Pathname
Constructor Details
Instance Method Details
#cwd ⇒ Pathname
111 112 113 |
# File 'lib/pikuri/tool/workspace.rb', line 111 def cwd @root end |
#resolve_for_read(path) ⇒ Pathname
118 119 120 |
# File 'lib/pikuri/tool/workspace.rb', line 118 def resolve_for_read(path) resolve(path) end |
#resolve_for_write(path) ⇒ Pathname
125 126 127 |
# File 'lib/pikuri/tool/workspace.rb', line 125 def resolve_for_write(path) resolve(path) end |