File name disambiguation weirdness in FileDataStore when replacing existing file #215

Closed
mdevs opened this Issue Aug 14, 2012 · 2 comments

Comments

Projects
None yet
3 participants

mdevs commented Aug 14, 2012

These is some disambiguation logic when replacing an existing file. For better or worse, here is the monkey-patch to fix:

module Dragonfly
  module DataStorage
    FileDataStore.class_eval do
      def store(temp_object, opts={})
        relative_path = if opts[:path]
                          opts[:path]
                        else
                          filename = temp_object.name || 'file'
                          relative_path = relative_path_for(filename)
                        end
        begin
          path = absolute(relative_path)
          temp_object.to_file(path).close
          store_meta_data(path, temp_object.meta) if store_meta
        rescue Errno::EACCES => e
          raise UnableToStore, e.message
        end

        relative(path)
      end
    end
  end
end

module Dragonfly
  module ActiveModelExtensions

    class Attachment
      def destroy_previous!
        if previous_uid
          destroy_content(previous_uid) unless uid == previous_uid
          self.previous_uid = nil
        end
      end
    end
  end
end

sigra commented Apr 23, 2013

You solve my problem! Thanks a lot

Owner

markevans commented Nov 25, 2013

I'm not sure if there's still a problem here since the code has been refactored for version 1 so closing

@markevans markevans closed this Nov 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment