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? -- Cheers, ioana k&a http://boulangerie.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060609/ec85a9b9/attachment.html
well, from the error message, it looks like you are not allowed to delete the file due to permissions. i would start there. On 6/9/06, Ioana Kanda <kaio4000@gmail.com> wrote:> > > 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? > -- > Cheers, > ioana k&a > http://boulangerie.wordpress.com/ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060609/536eaed4/attachment.html
What OS are you using for your server? On Jun 9, 2006, at 2:52 AM, Ioana Kanda wrote:> > 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? > -- > Cheers, > ioana k&a > http://boulangerie.wordpress.com/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060609/4fe8a717/attachment.html
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. -- Cheers, ioana k&a http://boulangerie.wordpress.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060609/cb711d3f/attachment.html
On 6/9/06, Ioana Kanda <kaio4000@gmail.com> 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).> File.delete("xml_26548975.xml") > But I get this error: > "Permission denied - ./script/../config/../uploads > /xml_26548975.xml ".Why? > -- > Cheers, > ioana k&a > http://boulangerie.wordpress.com/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- -Alder
Ioana Kanda 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, Bill Walton <bill.walton@charter.net> wrote:> Ioana Kanda 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > 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...) -- -Alder
Hi Alder, Alder Green wrote:> On 6/9/06, Bill Walton <bill.walton@charter.net> wrote: >> >> 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. >> > > 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
On 6/9/06, Bill Walton <bill.walton@charter.net> wrote:> Hi Alder, > > Alder Green wrote: > > On 6/9/06, Bill Walton <bill.walton@charter.net> wrote: > >> > >> 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. > >> > > > > 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > 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? -- -Alder