summaryrefslogtreecommitdiff
path: root/lib/dslkeywords
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-25 23:16:54 +0200
committerPaul Buetow <paul@buetow.org>2025-02-25 23:16:54 +0200
commit37eb90aebd8b26508d60f4ec623ae6192df5c09d (patch)
tree9d672855f6c0d9213c97c350e0926ddba4d54b1e /lib/dslkeywords
parent577d457b1bd0f09a91be2afa07a9f81c38cac8a2 (diff)
initial mode support
Diffstat (limited to 'lib/dslkeywords')
-rw-r--r--lib/dslkeywords/file.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index 39e0499..c1f55d3 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -58,6 +58,15 @@ module RCM
def manage(what) = @manage_directory = validate(__method__, what.to_sym, :directory) == :directory
def path(file_path = nil) = file_path.nil? ? @file_path : @file_path = file_path
def without(what) = @without_backup = validate(__method__, what.to_sym, :backup) == :backup
+ def mode(what) = @mode = what
+
+ def evaluate!
+ unless super
+ @mode = nil
+ return false
+ end
+ true
+ end
def content(text = nil)
if text.nil?
@@ -69,6 +78,14 @@ module RCM
protected
+ def mode!(file_path = path)
+ return if !::File.exist?(file_path) || @mode.nil?
+
+ dry? "Setting mode of #{file_path} to #{@mode}" do
+ FileUtils.chmod(@mode, file_path)
+ end
+ end
+
# Validate whether we can use this up in this context or not
def validate(method, what, *valids)
return what if valids.include?(what)
@@ -129,6 +146,8 @@ module RCM
create_parent_directory! if @manage_directory
write!(content)
+ ensure
+ mode!
end
private
@@ -187,6 +206,8 @@ module RCM
dry? "Creating symlink #{@file_path}" do
FileUtils.ln_sf(content, @file_path)
end
+ ensure
+ mode!
end
end
@@ -204,6 +225,8 @@ module RCM
FileUtils.touch(@file_path)
end
+ ensure
+ mode!
end
end
@@ -217,6 +240,8 @@ module RCM
when :absent, :purged
evaluate_absent!
end
+ ensure
+ mode!
end
def evaluate_present!