[how can i delete a file system..please help]

Hi,
I’m trying to delete a file system (<xml_26548975.xml>)
File.delete(“xml_26548975.xml”)
But I get this error:
“Permission denied - ./script/…/config/…/uploads/xml_26548975.xml”.
Why?

What OS are you using for your server?

well, from the error message, it looks like you are not allowed to
delete
the file due to permissions. i would start there.

I’m just uploading a file - copying the content to another file, which
afterwards I want to delete it/unlink it/get lost.

uploaded_file = RAILS_ROOT + “/uploads/xml_” + generate_code + “.xml”
File.open(uploaded_file, “wb”) do |f|
f.write(@file.read)

after some time…File.delete("…").

I’m using XP and WEBrick( I think he’s to blame).

Thanks for your time.

Ioana K. wrote:

uploaded_file = RAILS_ROOT + “/uploads/xml_” + generate_code + “.xml”

File.open(uploaded_file, "wb") do |f|
f.write(@file.read)

after some time…File.delete("…").

FileUtils.rm “#{uploaded_file}” should do what you’re looking for,
although
you may need to either stip off RAIL_ROOT or save the path without
RAILS_ROOT prior to the File.open. That is, I think FileUtils assumes
it’s
working from RAILS_ROOT whereas File does not.

hth,
Bill

On 6/9/06, Ioana K. [email protected] wrote:

Hi,
I’m trying to delete a file system (<xml_26548975.xml>)

A “file system”? xml_26548975.xml is a regular file, right? Since if
it’s a directory tree or something, you’re not using the correct
method (should look at Dir.delete instead).

If it is a file, the first thing I would check is if you’re trying to
File.delete it while it’s still open. The code below shows you’re
using a block scope for the output file, which is good since it takes
care of closing the file for you. However, looks like you’re not using
the same good pattern for the input file (@file). You can, and should
consider it, to avoid bugs like the one that might be haunting you
right now (there’s no problem nesting File.open blocks if that’s what
hindered you).

On 6/9/06, Bill W. [email protected] wrote:

[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Why would FileUtils assume its working from RAILS_ROOT? It’s a Ruby
library, not a Rails’ one. Does Ruby modify it in some way? (sounds a
bit unlikely…)

On 6/9/06, Bill W. [email protected] wrote:

working from RAILS_ROOT whereas File does not.

http://lists.rubyonrails.org/mailman/listinfo/rails

Check what’s the CWD (with Dir.pwd) in each phase. My guess is they
would be different - RAILS_ROOT for the #rm call, somehing else for
the #copy.

The CWD is dependent upon your stack setup. For example, with WEBrick
it’s often RAILS_DIR throughout the app, while with FastCGI and
Lighttpd it’s /public. What’s your setup?

Hi Alder,

Alder G. wrote:

Why would FileUtils assume its working from RAILS_ROOT? It’s a Ruby
library, not a Rails’ one. Does Ruby modify it in some way? (sounds a
bit unlikely…)

I don’t know. I’m just going on my recent experience. I’m doing a
little
app that includes a file upload. After looking back at that code more
closely, I’m just more confused. FileUtils.copy seems to need
RAILS_ROOT
but FileUtils.rm does not. Here’s the file upload code I’m using.

@filenametouse = “temp-readin” + nextfile.id.to_s + “.xml”

if params[:file_to_upload].instance_of?(Tempfile)
FileUtils.copy(params[:file_to_upload].local_path,
“#{RAILS_ROOT}/public/#{@filenametouse}”)
else
File.open("#{RAILS_ROOT}/public/#{@filenametouse}",“w”){|f|
f.write(params[:file_to_upload].read)
f.close}
end

I store the value of @filenametouse in a db record and later retrieve it
to
delete the file which I do with this code. (emrec.id just identifies
the
group of files I created in a session)

files = Tempfilerec.find(:all,
:conditions => [“emrec_id = ?”,
emrec.id])
files.each {|file|
FileUtils.rm “public/#{file.filename}”
}

I remember being confused when I got the code working but, under
deadline
pressure, just moved on with a note-to-self to come back later and
figure
out “why the difference?” Any ideas?

Best regards,
Bill