branch14
branch14

Reputation: 1262

Change Dragonfly (Gem) File Permissions (i.e. to 0664)

Dragonfly creates files by default with permissions set to 0644

From https://github.com/markevans/dragonfly/blob/master/lib/dragonfly/temp_object.rb#L116

def to_file(path, opts={})
  mode = opts[:mode] || 0644
  prepare_path(path) unless opts[:mkdirs] == false
  if @data
    File.open(path, 'wb', mode){|f| f.write(@data) }
  else
    FileUtils.cp(self.path, path)
    File.chmod(mode, path)
  end
  File.new(path, 'rb')
end

It seems like other permissions can be provided. But how?

Where it's called there is no options hash being passed in.

From https://github.com/markevans/dragonfly/blob/master/lib/dragonfly/file_data_store.rb#L107

content.to_file(path).close

Upvotes: 0

Views: 128

Answers (1)

branch14
branch14

Reputation: 1262

While this is not as clean as I like it to be, since it's coupled against implementation details of Dragonfly, I've found a way by means of guerilla patching...

In config/initializers/dragonfly.rb I added

class Dragonfly::Content
  def to_file(path)
    umask = File.umask(02)
    val = temp_object.to_file(path, mode: 0664)
    File.umask(umask)
    val
  end
end

Upvotes: 1

Related Questions