Saving files and permissions

having a file saving permissions problem from within a controller…

f = File.new("/home/path/to/I-A-files.txt", "w")
f.syswrite(output)
f.close

The error…

Errno::EACCES (Permission denied - /home/path/to/I-A-files.txt):

this file path is not within RAILS path but rather outside of it.

files saved without a path are clearly saved in the RAILS_ROOT directory
as user ‘craig’

user ‘craig’ clearly has permissions to save files in that path
(actually, the path is an NFS mounted path but I don’t see why that
should matter)

Obviously I am missing some bit of information that would tell me why
this fails.

TIA

Craig

how are you running rails? Through mongrel? Is your mongrel instance
running as user craig?

Mike

On Tue, 2008-03-11 at 22:11 -0400, Mike G. wrote:

how are you running rails? Through mongrel?


yes

Is your mongrel instance
running as user craig?


yes and as you can see, files ‘icalout.ics’ and ‘test.txt’ which are
created by my ‘rails application’ are definitely created by user ‘craig’

ls -l
drwxr-xr-x 8 craig users 4096 2007-10-11 11:32 app
drwxr-xr-x 3 craig users 4096 2007-10-11 11:33 components
drwxr-xr-x 4 craig users 4096 2008-01-31 16:07 config
drwxr-xr-x 4 craig users 4096 2007-10-11 11:33 db
drwxr-xr-x 3 craig users 4096 2007-12-28 09:38 doc
-rw-r–r-- 1 craig users 1105 2008-01-30 11:53 icalout.ics
drwxr-xr-x 4 craig users 4096 2008-03-04 16:57 lib
drwxrwxrwx 3 craig users 4096 2008-03-11 11:39 log
drwxr-xr-x 13 craig users 4096 2008-01-30 11:54 public
-rw-r–r-- 1 craig users 307 2007-10-11 11:34 Rakefile
-rw-r–r-- 1 craig users 6064 2007-10-11 11:34 README
drwxr-xr-x 5 craig users 4096 2007-10-11 11:33 script
drwxr-xr-x 7 craig users 4096 2007-10-11 11:32 test
-rw-rw-rw- 1 craig users 985 2008-03-11 15:18 test.txt
drwxrwxrwx 3 craig users 4096 2008-03-10 14:37 tmp
drwxr-xr-x 6 craig users 4096 2008-01-31 15:30 vendor

and the directory in question…

$ ls -ld /home/path/to/Build-PDF/
drwxrwsrwx 2 craig administrative 4096 2008-03-11
17:24 /home/path/to/Build-PDF/

user ‘craig’ clearly has write permissions and I’m clearly writing files
into that directory as user ‘craig’ outside of the ‘rails application’

Craig

are you absolutely sure mongrel is running as you? have you tried
printing whoami from one of your controllers to see who your code is
executing as?

On Tue, 2008-03-11 at 18:58 -0700, Craig W. wrote:

this file path is not within RAILS path but rather outside of it.

files saved without a path are clearly saved in the RAILS_ROOT directory
as user ‘craig’

user ‘craig’ clearly has permissions to save files in that path
(actually, the path is an NFS mounted path but I don’t see why that
should matter)

Obviously I am missing some bit of information that would tell me why
this fails.


OK - this is truly strange, because I can get it to work from
script/console but not from within my controller…(I have removed the

from the script/console output for readability).

 @qm_book = QmManual.find(:all, \
   :conditions => ["section = ?", "I/A"], \
   :order => 'priority')

=> [# Much data deleted… }>]
File.open(“I-A-files.txt”, “w”) do |file|
for qm_book in @qm_book
file.write “/home/path_to/New_QM_Manual/” +
qm_book.section + “/” + qm_book.file_name + “.pdf” + “\n”
if qm_book.no_of_pages.modulo(2) != 0
file.write
“/home/path/to/Build-PDF/blank-page.pdf” + “\n”
end
end
file.close
FileUtils.mv “I-A-files.txt”, “/home/path/to/Build-PDF/”
end
=> 1

but this same code in my controller gets the error that I listed up top.

why would file write permissions differ from script/console and
controller code? mongrel? mongrel is running as me - same user.

Craig

Good thought…I am just starting to tinker with backticks and executing
shell commands.

thus, in contoller code, flash[:notice] = whoami

just confirmed it is me, which I had to believe was the case since a
simple ps aux |grep mongrel also tells me the same thing.

The issue is somewhat confusing…

I am using various NFS mounts including my $HOME directory and I can
save files in that tree but not on other mounts. The curious thing is
that what works in script/console does not work in controller code so
I’m gathering that it has something to do with mongrel.

mongrel_cluster (1.0.2)
Mongrel plugin that provides commands and Capistrano tasks for
managing multiple Mongrel processes.

checking to see if there’s an update but I don’t hold out much hope for
it changing things

Craig

Maybe mongrel is running in a chroot jail? Have you checked what \ is
for it?

Doesn’t seem to be a chroot jail because I can save files on the out of
the RAILS_ROOT tree but I had to symlink the NFS mount into my
RAILS_ROOT to simplify the matter…it worked. I don’t know why and I
had to move on.

Craig

sort of solved anyway…I ended up making symbolic links from the target
directory into a directory inside my RAILS_ROOT path and I can now save
files, etc.

this is strange behavior…

Anyway, I wanted to leave tracks in case anyone follows down my path.

Craig

On my development system, it’s disabled

Craig

is your machine running SELinux? I’ve run into some very strange
behaviour on my server machine which runs Redhat with SELinux enabled.

Mike