"permission denied" happening too often

P

Peter Bailey

Hello,
I've got Ruby scripts that have been working fine for years now. But,
every now and then, one of my scripts errors out with a "permission
denied" error. This is very frustrating. Usually, it involves moving a
file to either a sister directory or a subdirectory. And, like I said,
99% of the time it works fine. Has anyone else experienced this? It kind
of scares me because it's only been happening for me with Ruby. It
didn't use to happen with Perl, and, believe, I don't want to go back to
Perl.

Thanks,
Peter
 
A

Anurag Priyam

I've got Ruby scripts that have been working fine for years now. But,
every now and then, one of my scripts errors out with a "permission
denied" error. This is very frustrating. Usually, it involves moving a
file to either a sister directory or a subdirectory. And, like I said,
99% of the time it works fine. Has anyone else experienced this? It kind
of scares me because it's only been happening for me with Ruby. It
didn't use to happen with Perl, and, believe, I don't want to go back to
Perl.

Can you post your code? Not sure, but trying to move '.' or '..' on a
Unix system might cause this problem. Also, did you verify that you
have right permissions on the files, and directories?
 
M

Markus Schirp

You can also try to strace your script. In the logs you'll find the system
call causing the Permission denied...
 
P

Peter Bailey

Anurag Priyam wrote in post #980286:
Can you post your code? Not sure, but trying to move '.' or '..' on a
Unix system might cause this problem. Also, did you verify that you
have right permissions on the files, and directories?

Yes, I know I have the rights. It's on a Windows server. And, I'm doing
a "FileUtils.mv" command. And, like I said, it works 99% of the time.
Cheers.
 
P

Peter Bailey

Markus Schirp wrote in post #980289:
You can also try to strace your script. In the logs you'll find the
system
call causing the Permission denied...

strace? Hmmm. Never heard of that. I'll have to look into it.

Thanks.
 
J

Jeremy Bopp

Markus Schirp wrote in post #980289:

strace? Hmmm. Never heard of that. I'll have to look into it.

Given that you're on Windows, you don't have strace; however, Process
Monitor from SysInternals
(http://technet.microsoft.com/en-us/sysinternals/bb896645) should be
able to do much the same operation.

The likely problem though is that some other process, or even that
running your script, still has one of the files or directories you're
trying to move open and in use. Common culprits are virus scanners, so
if you have one of those, you might try temporarily disabling it and see
if that eliminates your problem. In rare cases, it is necessary to
remove such offending software entirely.

-Jeremy
 
P

Peter Bailey

Jeremy Bopp wrote in post #980293:
Given that you're on Windows, you don't have strace; however, Process
Monitor from SysInternals
(http://technet.microsoft.com/en-us/sysinternals/bb896645) should be
able to do much the same operation.

The likely problem though is that some other process, or even that
running your script, still has one of the files or directories you're
trying to move open and in use. Common culprits are virus scanners, so
if you have one of those, you might try temporarily disabling it and see
if that eliminates your problem. In rare cases, it is necessary to
remove such offending software entirely.

-Jeremy

I don't have the right to disable the virus scanner on this server.
That's controlled by IT guys. I'll look into the SysInternals thing.
I've used their stuff before. Thanks.
 
K

Kirk Haines

I don't have the right to disable the virus scanner on this server.
That's controlled by IT guys. I'll look into the SysInternals thing.
I've used their stuff before. Thanks.

The nutshell here is that something -- possibly the virus scanner or
possibly some other software -- is touching the file when your script
runs, altering the permissions such that your script can't do what
it's trying to do. The problem isn't something unique to or endemic to
Ruby -- it's just a fundamental permissions issue. The solution is
simple. You just need to handle the exception that is generated.

begin
#
# Your code here.
#
FileUtils.mv("a","b")
rescue Errno::EACCES
#
# Well, dang. No permissions. So, do something to deal with it.
#
# You could sleep and 'retry', though you probably want to implement a
# counter if you do that so that you aren't stuck in a loop forever.
#
# You could just write the offending file to a log somewhere.
#
end


Kirk Haines
Engine Yard
 
J

Jeremy Bopp

I don't have the right to disable the virus scanner on this server.
That's controlled by IT guys.

Ask them if they have recently updated or reconfigured the virus scanner
or any similar file scanning service on the server. It's possible that
they may make further changes to work around the issue if you can
convince them that their most recent changes broke something important.

-Jeremy
 
J

Jeremy Bopp

The nutshell here is that something -- possibly the virus scanner or
possibly some other software -- is touching the file when your script
runs, altering the permissions such that your script can't do what
it's trying to do.

Just to be clear. It's not that something is changing the ACLs on the
file or anything. Rather, a file or directory that is in use by another
program cannot be removed or relocated on Windows without some ugly
trickery. This is a limitation of Windows itself.

I know that Cygwin implements some of the hacks to make it at least
appear possible to move and delete in-use files. You could try running
your scripts with Cygwin's Ruby package to see if that helps things, but
be aware that the performance as a whole will likely suffer a bit.

-Jeremy
 
K

Kirk Haines

Just to be clear. =A0It's not that something is changing the ACLs on the
file or anything. =A0Rather, a file or directory that is in use by anothe= r
program cannot be removed or relocated on Windows without some ugly
trickery. =A0This is a limitation of Windows itself.

Right. I was just being intentionally general in my phrasing, since
the advice is applicable to anyone writing code to move files around,
regardless of OS.


Kirk Haines

Unhandled exceptions are ugly. Make the world more beautiful, and
handle yours today.
 
P

Peter Bailey

Jeremy Bopp wrote in post #980325:
Ask them if they have recently updated or reconfigured the virus scanner
or any similar file scanning service on the server. It's possible that
they may make further changes to work around the issue if you can
convince them that their most recent changes broke something important.

-Jeremy

I'll do that. Thanks.
 
J

Jeremy Bopp

Right. I was just being intentionally general in my phrasing, since
the advice is applicable to anyone writing code to move files around,
regardless of OS.

Yeah, I figured as much. I just wanted to make sure that others reading
this in the forum later would be sure to understand this issue in
particular. Given the description of the problem, you probably wouldn't
ever see this kind of error on a Unix system unless some program
actually did change the permissions on the file or directory itself
rather than just have it open as is likely the case here. :)

-Jeremy
 
P

Peter Bailey

Jeremy Bopp wrote in post #980452:
Yeah, I figured as much. I just wanted to make sure that others reading
this in the forum later would be sure to understand this issue in
particular. Given the description of the problem, you probably wouldn't
ever see this kind of error on a Unix system unless some program
actually did change the permissions on the file or directory itself
rather than just have it open as is likely the case here. :)

-Jeremy

I'll just put in some exception handling, as suggested. And, I'll ask my
IT guys if the virus scanner might be a culprit here. I'm a little
concerned about his maybe just being a Windows problem.
 
J

Jeremy Bopp

I'm a little
concerned about his maybe just being a Windows problem.

What is the concern exactly? People have had to deal with the inability
to remove or relocate in-use files and directories on Windows for quite
a long time, so there is usually a way to avoid the cause of the issue
once identified. For instance, if the AV software is actually the
problem, the fix may be as simple as configuring the AV software to
avoid scanning in the directory structure in which your script operates.

-Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top