gma / nesta

File Based CMS and Static Site Generator
http://nestacms.com
MIT License
902 stars 121 forks source link

"No such file or directory" error thrown in cache.rb #109

Closed briangonzalez closed 10 years ago

briangonzalez commented 12 years ago

I deployed a Nesta site to my CentOS server running Passenger/nginx and received the following error:

No such file or directory
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/nesta-0.9.13/lib/nesta/cache.rb:34:in `cache'

I was also able to reproduce the error locally on OSX Lion on my Macbook Pro, which makes me think the issue is not limited to subtlety on my server.

I can only reproduce the error using the bleeding edge version of Nesta (from Github) and setting cache: true in Nesta's config.yml.

Using Ruby 1.9.2 and Sinatra 1.3.

gma commented 12 years ago

That clarifies it wonderfully, thanks.

gma commented 12 years ago

I've tested caching on my localhost with shotgun, and it works fine. I used commit 858af82c8b0627f6621ad9fcbcfdb26f7118cd4a, but it's essentially identical from a caching perspective to the one you tried.

My suspicion is that your problem is to do with how Passenger is configured. When you reproduced the error locally was that with Passenger, or can you get it to break with shotgun or rackup too?

gma commented 12 years ago

I was just reading the code in cache.rb. I think it might be passing an empty string to FileUtils.mkdir_p, which would suggest that in the environment you're running that code the path variable that's defined on line 33 doesn't have a directory prefix on it. From reading the code I can't see how this would occur, but it's not something that I'd expect to be passenger's "fault" as the path is determined from Rack's request.path_info method.

I'm tempted to just rip this cache.rb file out and replace it with sinatra-cache. It's long overdue anyway…

gma commented 12 years ago

I've got a branch of Nesta that does away with this old caching code.

@briangonzalez - Would you be up for installing Nesta from that branch and taking the docs for a spin? I think it might solve your problem, especially given that you can easily override the path to the folder where cached files should be stored (with the cache_output_dir setting).

The commit with the docs in is here: gma/nestacms.com@9b559eb27bd1d2722640aa799597f86ff3a38bf3

The new version of Nesta is on the sinatra-cache branch of gma/nesta. You can install it with bundler by following these instructions: http://nestacms.com/docs/recipes/running-the-latest-code

Cheers!

:-)

briangonzalez commented 12 years ago

Graham,

I've just been tinkering around a little with the sinatra-cache branch, and even on my production server running CentOS/Passenger, all seems to be working fine. Great work.

I found through some inspection over the past hour or so that my cache problems were in my config.ru file.

Since I was using others' examples as a starting point, I must have grabbed an old config.ru that was missing these lines:

use Rack::ConditionalGet
use Rack::ETag

require 'nesta/env'
Nesta::Env.root = ::File.expand_path('.', ::File.dirname(__FILE__))

Adding them solved my cache.rb issues.

I'll bang around more on the sinatra-cache branch tonight when I get home from work. Thanks Graham!

briangonzalez commented 12 years ago

Perhaps we should close this issue?

gma commented 12 years ago

Glad to hear it's working okay. In config.ru you won't need the two use lines unless you want to serve the HTTP headers they produce (they're a good idea, but unrelated to the caching problem). It's the missing root setting that explains why caching was breaking for you. Sinatra's settings.public_folder path is derived from the root folder, and that in turn was used inside cache.rb.

I'll close this issue once I've merged the sinatra-cache branch onto master; for the moment it's serving as a reminder in the 0.10.0 milestone of what I still want to get done before 0.10.0.

I'll merge the sinatra-cache branch and mark this as closed just before 0.10.0 so that the public docs are correct for anybody who wants to install Nesta from master in the meantime…

gma commented 12 years ago

Note to self; before merging the sinatra-cache branch onto master make sure that it runs fine on sites that have defined their own routing actions that call the cache helper.

gma commented 10 years ago

I've just removed lib/nesta/cache.rb, which solves this.