This project is archived and is in readonly mode.

#1962 ✓resolved

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

Reported by brunetton | February 13th, 2009 @ 04:34 PM | in 2.x

Hi all,

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


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}.#{}.#{rand(1000000)}"`

To correct this :

check_name = join(dirname(file_name), ".permissions_check.#{Thread.current.object_id}.#{}.#{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

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>