Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to fix "first snapshot is not read-only" issue #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/snapsync/btrfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ def self.generation_of(path)
end
end

# Facade for checking readonly-flag on snapshot using 'btrfs subvolume show'
#
# @param [Pathname] path the subvolume path
# @return [Boolean] if the snapshot is readonly
def self.readonly(path)
info = Btrfs.run('subvolume', 'show', path.to_s)
if info =~ /Flags[^:]*:\s+(-|\w+)/
"readonly" == $1.to_s
else
raise UnexpectedBtrfsOutput, "unexpected output for 'btrfs subvolume show', expected #{info} to contain a Flags: line"
end
end

# Facade for 'btrfs subvolume find-new'
#
# It computes what changed between a reference generation of a
Expand Down
7 changes: 6 additions & 1 deletion lib/snapsync/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def self.each_snapshot_raw(snapshot_dir)
if path.directory? && path.basename.to_s =~ /^\d+$/
begin
snapshot = Snapshot.new(path)
yield(path, snapshot, nil)
readonly = Btrfs.readonly(snapshot.subvolume_dir())
if readonly
yield(path, snapshot, nil)
else
Snapsync.info "found non-read-only snapshot #{path}"
end
rescue InvalidSnapshot => e
yield(path, nil, e)
end
Expand Down