Forum: Ruby "permission denied"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter B. (Guest)
on 2009-02-20 15:46
Hi,
I'm frustrated with one of my Ruby scripts. It's an image processing
script that converts [sometimes thousands] of images and then HTTPs on
to archival servers. I continue to get a "permission denied" error on
one out of many files. Below is a subset of the PNG portion of my
script, with the error in question. All of the TIFFs, EPSs, and PDFs
were sent successfully. I just don't understand why some files get this
error. Obviously, it stops the whole script.

Thanks,
Peter

...
 success = ProdOrca.sendPNG pngfile
  if success == true then
  ftpfile = File.new(filesuccess, "w")
  ftp.putbinaryfile(filesuccess)
  ftpfile.close
  File.open("E:/logs/StatusReports/InfoConFiles.log", ...
 else
  ftpfile = File.new(fileerror, "w")
  ftp.putbinaryfile(fileerror)
  ftpfile.close
  File.open("E:/logs/StatusReports/InfoConFiles.log", ...
 end
  FileUtils.rm(pngfile)  <----- This is what it's complaining about.
...

Exception: Permission denied - EC11SE91-043.png
Choi, Junegunn (Guest)
on 2009-02-20 16:41
(Received via mailing list)
2009/2/20 Peter B. <removed_email_address@domain.invalid>:
>  FileUtils.rm(pngfile)  <----- This is what it's complaining about.
> ...
> Exception: Permission denied - EC11SE91-043.png
>

This may sound silly, but do you really have write permissions to
those files? I don't think it's about your script. You can't delete a
file if you don't have write permission to it.
Lars C. (Guest)
on 2009-02-20 16:45
(Received via mailing list)
On Feb 20, 2:46 pm, Peter B. <removed_email_address@domain.invalid> wrote:
> Hi,
> I'm frustrated with one of my Ruby scripts. It's an image processing
> script that converts [sometimes thousands] of images and then HTTPs on
> to archival servers. I continue to get a "permission denied" error on
> one out of many files. Below is a subset of the PNG portion of my
> script, with the error in question. All of the TIFFs, EPSs, and PDFs
> were sent successfully. I just don't understand why some files get this
> error. Obviously, it stops the whole script.

Are you running on Windows and using a virus scanner? We've seen very
similar problems with Symantec Antivirus on Windows XP. Only solutions
are to disable the virus scanner OR "retry" deleting the file until it
works.
Peter B. (Guest)
on 2009-02-20 16:47
Choi, Junegunn wrote:
> 2009/2/20 Peter B. <removed_email_address@domain.invalid>:
>>  FileUtils.rm(pngfile)  <----- This is what it's complaining about.
>> ...
>> Exception: Permission denied - EC11SE91-043.png
>>
>
> This may sound silly, but do you really have write permissions to
> those files? I don't think it's about your script. You can't delete a
> file if you don't have write permission to it.

Thanks for your reply. Yes, I do have permission. I'm a full
administrator of this server and everything on it. It's a Windows
server.
Peter B. (Guest)
on 2009-02-20 16:49
Lars C. wrote:
> On Feb 20, 2:46�pm, Peter B. <removed_email_address@domain.invalid> wrote:
>> Hi,
>> I'm frustrated with one of my Ruby scripts. It's an image processing
>> script that converts [sometimes thousands] of images and then HTTPs on
>> to archival servers. I continue to get a "permission denied" error on
>> one out of many files. Below is a subset of the PNG portion of my
>> script, with the error in question. All of the TIFFs, EPSs, and PDFs
>> were sent successfully. I just don't understand why some files get this
>> error. Obviously, it stops the whole script.
>
> Are you running on Windows and using a virus scanner? We've seen very
> similar problems with Symantec Antivirus on Windows XP. Only solutions
> are to disable the virus scanner OR "retry" deleting the file until it
> works.

Thanks for your replay. Yes, unfortunately, our IT staff uses Norton
Anti-Virus on this Windows server. I personally use Nod32 on my PC, but,
I don't think I have a choice on the server. But, I will see if I can
turn Norton off temporarily while I run my script.
Hassan S. (Guest)
on 2009-02-20 17:08
(Received via mailing list)
On Fri, Feb 20, 2009 at 5:46 AM, Peter B. <removed_email_address@domain.invalid> 
wrote:

> error. Obviously, it stops the whole script.

> Exception: Permission denied - EC11SE91-043.png

Why "obviously"? Can't you just rescue that exception, log the error,
and continue (or retry, if that makes more sense)?  :-)
Peter B. (Guest)
on 2009-02-20 18:14
Hassan S. wrote:
> On Fri, Feb 20, 2009 at 5:46 AM, Peter B. <removed_email_address@domain.invalid> wrote:
>
>> error. Obviously, it stops the whole script.
>
>> Exception: Permission denied - EC11SE91-043.png
>
> Why "obviously"? Can't you just rescue that exception, log the error,
> and continue (or retry, if that makes more sense)?  :-)

Well, I've already spent a week or so putting in exception handling for
other parts of this script. I'm not very good at exception handling,
frankly. I guess I can try to do it for this as well. But, I still would
like to know why it's having the problem in the first place. What I'm
doing now is simply doing smaller batches of files. Instead of doing
1,200 files at once, I'm doing about a hundred at a time. Thanks.
Igor P. (Guest)
on 2009-02-20 21:10
Peter B. wrote:
> Hi,
> I'm frustrated with one of my Ruby scripts. It's an image processing
> script that converts [sometimes thousands] of images and then HTTPs on
> to archival servers. I continue to get a "permission denied" error on
> one out of many files.

Why not implementing something like the following to salvage your
processing, document (LOG) the problem and deal with it latter:

...
 success = ProdOrca.sendPNG pngfile
  if success == true then
  ftpfile = File.new(filesuccess, "w")
  ftp.putbinaryfile(filesuccess)
  ftpfile.close
  File.open("E:/logs/StatusReports/InfoConFiles.log", ...
 else
  ftpfile = File.new(fileerror, "w")
  ftp.putbinaryfile(fileerror)
  ftpfile.close
  File.open("E:/logs/StatusReports/InfoConFiles.log", ...
 end
 ####### Salvage your operation and log the problematic files ######
 begin
  FileUtils.rm(pngfile)  <----- This is what it's complaining about.
 rescue
  puts "LOG: #{File.expand_path(file)} can not be handled"
 end
...
Peter B. (Guest)
on 2009-02-20 21:24
Igor P. wrote:
> Peter B. wrote:
>> Hi,
>> I'm frustrated with one of my Ruby scripts. It's an image processing
>> script that converts [sometimes thousands] of images and then HTTPs on
>> to archival servers. I continue to get a "permission denied" error on
>> one out of many files.
>
> Why not implementing something like the following to salvage your
> processing, document (LOG) the problem and deal with it latter:
>
> ...
>  success = ProdOrca.sendPNG pngfile
>   if success == true then
>   ftpfile = File.new(filesuccess, "w")
>   ftp.putbinaryfile(filesuccess)
>   ftpfile.close
>   File.open("E:/logs/StatusReports/InfoConFiles.log", ...
>  else
>   ftpfile = File.new(fileerror, "w")
>   ftp.putbinaryfile(fileerror)
>   ftpfile.close
>   File.open("E:/logs/StatusReports/InfoConFiles.log", ...
>  end
>  ####### Salvage your operation and log the problematic files ######
>  begin
>   FileUtils.rm(pngfile)  <----- This is what it's complaining about.
>  rescue
>   puts "LOG: #{File.expand_path(file)} can not be handled"
>  end
> ...

Guess what? That's exactly what I did. Thanks a lot for your suggestion.
Begin/Rescue comes through for me again. I realized that FileUtils would
be full of "raises" and "exceptions," so, a begin/rescue should work
just fine. I'm running the script now on about 1,400 files.
Roger P. (Guest)
on 2009-02-21 20:47
>   FileUtils.rm(pngfile)  <----- This is what it's complaining about.
> ...
>
> Exception: Permission denied - EC11SE91-043.png

that usually means that some process still has the file open.  You could
use something like unlocker to try to determine if it has a lock on it.
-=r
Peter B. (Guest)
on 2009-02-22 04:57
Roger P. wrote:
>
>>   FileUtils.rm(pngfile)  <----- This is what it's complaining about.
>> ...
>>
>> Exception: Permission denied - EC11SE91-043.png
>
> that usually means that some process still has the file open.  You could
> use something like unlocker to try to determine if it has a lock on it.
> -=r

Thanks, Roger. I'll google around to see what "unlocker" is. Never heard
of it.
This topic is locked and can not be replied to.