From 25f3947c16b57a9686500534e44423aab90b0bc7 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 9 Nov 2016 09:30:12 +0000 Subject: First pass at fixing btrfs path This replaces the call to /sbin/btrfs with a method to find a btrfs program, which raises ENOENT if one cannot be found. --- lib/byteback/backup_directory.rb | 9 +++++++-- lib/byteback/util.rb | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/byteback') diff --git a/lib/byteback/backup_directory.rb b/lib/byteback/backup_directory.rb index 14a55cf..53491ff 100644 --- a/lib/byteback/backup_directory.rb +++ b/lib/byteback/backup_directory.rb @@ -1,6 +1,11 @@ +require 'byteback/utils' + module Byteback # Represents a particular timestamped backup directory class Snapshot + + include Byteback::Util + class << self # What order to remove snapshots in to regain disk space? # @@ -111,11 +116,11 @@ module Byteback end def create!(from) - system_no_error("/sbin/btrfs subvolume snapshot #{from} #{path}") + system_no_error("#{btrfs_bin} subvolume snapshot #{from} #{path}") end def delete! - system_no_error("/sbin/btrfs subvolume delete #{path}") + system_no_error("#{btrfs_bin} subvolume delete #{path}") end # Returns the size of the given snapshot (runs du, may be slow) diff --git a/lib/byteback/util.rb b/lib/byteback/util.rb index 9a993d6..07d7056 100644 --- a/lib/byteback/util.rb +++ b/lib/byteback/util.rb @@ -66,5 +66,12 @@ module Byteback pid2, status = Process.waitpid2(pid, 0) status.exitstatus end + + def btrfs_bin + path = '/bin/btrfs' + path = '/sbin/btrfs' unless File.exists?(path) + path + end + end end -- cgit v1.2.1 From b310c2f150a4802d63d492cfe3dfae650ebbc41e Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 9 Nov 2016 09:43:07 +0000 Subject: Raise ENOENT if btrfs cannot be found --- lib/byteback/util.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/byteback') diff --git a/lib/byteback/util.rb b/lib/byteback/util.rb index 07d7056..ebf5ca5 100644 --- a/lib/byteback/util.rb +++ b/lib/byteback/util.rb @@ -68,9 +68,10 @@ module Byteback end def btrfs_bin - path = '/bin/btrfs' - path = '/sbin/btrfs' unless File.exists?(path) - path + %w(/bin/btrfs /sbin/btrfs).each do |path| + return path if File.exist?(path) + end + raise Errno::ENOENT, 'btrfs' end end -- cgit v1.2.1 From 51ff72f7b458909071c4a42dbd25ab28ac16f3f8 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 31 Jan 2017 11:39:39 +0000 Subject: Update util.rb --- lib/byteback/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/byteback') diff --git a/lib/byteback/util.rb b/lib/byteback/util.rb index ebf5ca5..d70888b 100644 --- a/lib/byteback/util.rb +++ b/lib/byteback/util.rb @@ -69,7 +69,7 @@ module Byteback def btrfs_bin %w(/bin/btrfs /sbin/btrfs).each do |path| - return path if File.exist?(path) + return path if File.executable?(path) end raise Errno::ENOENT, 'btrfs' end -- cgit v1.2.1