# File.new text writing securtiy issue

**URL:** <https://www.ruby-forum.com/t/file-new-text-writing-securtiy-issue/140903>\
**Category:** Rails\
**Created:** [June 19, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/file-new-text-writing-securtiy-issue/140903 "2008-06-19T17:36:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oshuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ea5d25/32.png) [@oshuma](https://www.ruby-forum.com/u/oshuma)\
**Post date:** [June 19, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/file-new-text-writing-securtiy-issue/140903/1 "2008-06-19T17:36:51Z")

</div>

Ok so I’m working on a project that stores a number of users details and  
their associated mailing lists then after all edits writes all the .ali  
files to a directory.

I’m using the following code as a test of file.new (Which I haven’t used  
before).

txtout\_file =  
File.new("/export/machinename/htdocs/users/public/mailaliases/all.ali",“w+”)  
txtout\_file \<\< “Some random text” #write output to the file  
txtout\_file.close #close the file

This should write the line “Some random text” to the file all.ali, and  
it does as long as all.ali already exists. If all.ali is not in the  
directory it fails with the following error “Permission denied -  
/export/machinename/htdocs/users/public/mailaliases/all.ali”

I was under the impression that the w+ mode would create a file if the  
file did not exist. The folder permissions are correct as far as I can  
see and yet I cannot get rails to create the all.ali file.

Any ideas?
