Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/snapsync/remote_pathname.rb

Direct Known Subclasses

Snapsync::LocalPathname

Defined Under Namespace

Classes: NonZeroExitCode

Instance Method Summary collapse

Instance Method Details

#findmntObject



15
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
# File 'lib/snapsync/remote_pathname.rb', line 15

def findmnt
  # An optimization to quickly get the mountpoint.
  # 3 levels are needed to get from `.snapshots/<id>/snapshot` to a cached entry.
  # Will probably be fine.
  cached = Snapsync._mountpointCache.fetch(self.to_s, nil)
  cached = Snapsync._mountpointCache.fetch(self.parent.to_s, nil) unless cached
  cached = Snapsync._mountpointCache.fetch(self.parent.parent.to_s, nil) unless cached
  return cached.dup if cached

  Snapsync.debug "Pathname ('#{self}').findmnt"

  proc = IO.popen(Shellwords.join ['findmnt','-n','-o','TARGET','-T', self.to_s])
  path = proc.read.strip
  proc.close
  if not $?.success?
    raise NonZeroExitCode, "findmnt failed for #{self}"
  end

  raise "findmnt failed" unless path
  p = Pathname.new path
  # Update cache
  p2 = self.dup
  while p != p2
    Snapsync._mountpointCache[p2.to_s] = p
    p2 = p2.parent
  end
  p
end

#path_partObject



7
8
9
# File 'lib/snapsync/remote_pathname.rb', line 7

def path_part
  to_s
end

#touchObject



11
12
13
# File 'lib/snapsync/remote_pathname.rb', line 11

def touch
  FileUtils.touch(to_s)
end