I've resolved the problem or at least it works okay now.

My code looked like this:

def flush_deletes #:nodoc:
        logger.info("[paperclip] Deleting files for #{name}")
        @queued_for_delete.each do |path|
          begin
            logger.info("[paperclip] -> #{path}")
            FileUtils.rm(path) if File.exist?(path)
          rescue Errno::ENOENT => e
            # ignore file-not-found, let everything else pass
          end
          begin
            while(true)
              path = File.dirname(path)
              FileUtils.rmdir(path)
            end
rescue Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR
            # Stop trying to remove parent directories
          end
        end
        @queued_for_delete = []
      end

When I compared it to Oldham's code I noticed that mine had this extra:

         begin
            while(true)
              path = File.dirname(path)
              FileUtils.rmdir(path)
            end
rescue Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR
            # Stop trying to remove parent directories
          end

Once I removed it the extension worked without error.

Thanks for your help.


Steven






On Jan 28, 2009, at 1:03 PM, C. R. Oldham wrote:


On Jan 28, 2009, at 11:49 AM, Sean Cribbs wrote:

Sounds like paperclip should use FileUtils.rm_rf instead of rm_dir.

It doesn't, at least if it is the same as the one I have installed. Here's the code:

     def flush_deletes #:nodoc:
       logger.info("[paperclip] Deleting files for #{name}")
       @queued_for_delete.each do |path|
         begin
           logger.info("[paperclip] -> #{path}")
           FileUtils.rm(path) if File.exist?(path)
         rescue Errno::ENOENT => e
           # ignore file-not-found, let everything else pass
         end
       end
       @queued_for_delete = []
     end
   end

File.exist? returns true for files and directories. But unless I have an old version of paperclipped that doesn't call FileUtils.rm, the Ruby docs say specifically that FileUtils.rm does not remove directories. And to be really safe, it should use FileUtils.remove_entry_secure.

Steven, you might try a quick patch and change FileUtils.rm to FileUtils.remove_entry_secure (or FileUtils.rm_rf like Sean suggests if you are not terribly worried about security) in vendor/extensions/ paperclipped/vendor/plugins/paperclip/lib/paperclip/storage.rb

--cro

_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to