Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Cache fragment file creation error : "Couldn't create cache directory: ** (Permission denied - .permissions_check.-**)"

#1962

Hi all,

In brief Under certain conditions, fragment cache file creation isn't done (while it's possible).

Error

Couldn't create cache directory: views/menu_onglets (Permission denied - .permissions_check.-605420708.8937.647701)
Cached fragment miss: views/menu_onglets (0.5ms)

Conditions This error comes when : * ActionController::Base.cache_store isn't default (set to RAILS_ROOT/tmp/cache for example, useful to clearly separate cache files when multiple Rails apps are hosted on the same server and to have an empty cache after each Capistrano deploy) * and RAILS_ROOT isn't writable by Rails process

Description (assuming there is no cache files at all) * ActiveSupport::Cache::write() calls File::atomic_write() (defined in activesupport/lib/active_support/core_ext/file/atomic.rb) with a temp_dir argument * atomic_write()

* successfully creates the temp cache file (*temp_file*) in *temp_dir* with the fragment
* tries to get original file stats (because it's the first write) and executes the *rescue* block. This is normal

Problem and solution The code in the rescue block is intended to determine the default cache dir permissions (old_stat) by creating a temporary empty file.

The problem is that the temp file used for permissions (check_name) isn't created in the cache dir, but in current dir (RAILS_ROOT) :


check_name = ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}"`

To correct this :


check_name = join(dirname(file_name), ".permissions_check.#{Thread.current.object_id}.#{Process.pid}.#{rand(1000000)}")

(patch joined)

Additional infos Rails version : 2.2.2 (I suppose it's also the case in 2.2.3 branch) Server : Mongrel or Apache/modrails/ree

Reported by brunetton · February 13th, 2009 @ 04:34 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. brunetton
    brunetton

    Sorry for formatting problems in description

    Again :

    Description (assuming there is no cache files at all)

    • ActiveSupport::Cache::write() calls File::atomic_write() (defined in activesupport/lib/active_support/core_ext/file/atomic.rb) with a temp_dir argument
    • atomic_write()
    • successfully creates the temp cache file (temp_file) in temp_dir with the fragment
    • tries to get original file stats (because it's the first write) and executes the rescue block. This is normal

    February 13th, 2009 @ 04:46 PM

  2. brunetton
    brunetton

    the last two points were supposed to be indented. I tried first in Dingus (official Markdown sandbox)

    February 13th, 2009 @ 04:50 PM

  3. Pratik
    Pratik
    • Assigned user set to josh

    February 18th, 2009 @ 03:53 PM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [3d15e1a7b5c996baf11728ed32945b0d27418b1a]) Make atomic_write() puts the check_file in the cache dir, not in application root [#1962 Cache fragment file creation error : "Couldn't create cache directory: ** (Pe... state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    February 20th, 2009 @ 03:02 AM

  5. Repository
    Repository

    (from [3668a641702b6d0e5df963f54de8d17c53d6179c]) Make atomic_write() puts the check_file in the cache dir, not in application root [#1962 Cache fragment file creation error : "Couldn't create cache directory: ** (Pe... state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    February 20th, 2009 @ 03:02 AM