Skip to content

Commit

Permalink
Fix NFS exports pruning of other users. Issue 9070.
Browse files Browse the repository at this point in the history
  • Loading branch information
kotsis committed Nov 17, 2024
1 parent 216835c commit a243fd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/vagrant/util/string_block_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def keys
end
end

# This returns the keys (or ids) that are in the string regarding current user only (fix for issue 9070).
#
# @return [<Array<String>]
def cur_user_keys
regexp = /^#\s*VAGRANT-BEGIN:\s*(#{Process.uid}\s.+?)$\r?\n?(.*)$\r?\n?^#\s*VAGRANT-END:\s(\1)$/m
@value.scan(regexp).map do |match|
match[0]
end
end

# This deletes the block with the given key if it exists.
def delete(key)
key = Regexp.quote(key)
Expand Down
5 changes: 4 additions & 1 deletion plugins/hosts/linux/cap/nfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def self.nfs_prune(environment, ui, valid_ids)
composite_ids = valid_ids.map do |v_id|
"#{user} #{v_id}"
end
remove_ids = editor.keys - composite_ids

#Fix for issue 9070, pruning other users' NFS exports
#remove_ids = editor.keys - composite_ids
remove_ids = editor.cur_user_keys - composite_ids

logger.debug("Known valid NFS export IDs: #{valid_ids}")
logger.debug("Composite valid NFS export IDs with user: #{composite_ids}")
Expand Down

0 comments on commit a243fd8

Please sign in to comment.