File locking (Not Flock)
am 28.08.2007 20:39:59 von Bill HIs there a perl / linux way of locking a file? Not the FLOCK method
when you open a file, but setting the actual file as read only, or
read / write?
Bill H
Is there a perl / linux way of locking a file? Not the FLOCK method
when you open a file, but setting the actual file as read only, or
read / write?
Bill H
On Aug 28, 2:39 pm, Bill H
> Is there a perl / linux way of locking a file? Not the FLOCK method
> when you open a file, but setting the actual file as read only, or
> read / write?
my $cnt = chmod 0755, 'foo', 'bar';
On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
> On Aug 28, 2:39 pm, Bill H
>
> > Is there a perl / linux way of locking a file? Not the FLOCK method
> > when you open a file, but setting the actual file as read only, or
> > read / write?
>
> my $cnt = chmod 0755, 'foo', 'bar';
I was hoping to avoid using permissions, but I guess there isn't a
simple read only - read / write attribute in linux like in DOS. Thanks
Bill H wrote:
> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
>
>> On Aug 28, 2:39 pm, Bill H
>>
>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>> when you open a file, but setting the actual file as read only, or
>>> read / write?
>>
>> my $cnt = chmod 0755, 'foo', 'bar';
>
> I was hoping to avoid using permissions, but I guess there isn't a
> simple read only - read / write attribute in linux like in DOS. Thanks
You seem to be confused. File permissions/attributes are a matter of the
file system, not the operating system.
Because DOS doesn't know any fileystem but FAT I guess you are talking about
read/write attributes for FAT.
First of all of course you can use FAT also in Linux although no sane person
would recommend to do so.
Now if you want the same functionality as FAT read/write attributes on a
unixoid file system then file permissions are the correct answer as can
easily be seen by the customary
-rwxrwxrwx
They just provide a finer granularity of options which is an absolut
requirement because of the multi-user nature of Linux.
If you want to set the file to read-only just remove the w for all three
groups:
-r-xr-xr-x
jue
On 08/28/2007 03:47 PM, Bill H wrote:
> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
>
>> On Aug 28, 2:39 pm, Bill H
>>
>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>> when you open a file, but setting the actual file as read only, or
>>> read / write?
>> my $cnt = chmod 0755, 'foo', 'bar';
>
> I was hoping to avoid using permissions, but I guess there isn't a
> simple read only - read / write attribute in linux like in DOS. Thanks
>
I'm not sure about this, but I think you'd do better locking the file
this way:
my $cnt = chmod 0444, 'foo', 'bar';
Test if a file is "unlocked" this way:
if (-w 'foo') {
... write to 'foo' ...
}
Read these:
perldoc -f chmod
perldoc -f -w
On 2007-08-28, Mumia W.
> On 08/28/2007 03:47 PM, Bill H wrote:
>> On Aug 28, 2:48 pm, it_says_BALLS_on_your forehead
>>
>>> On Aug 28, 2:39 pm, Bill H
>>>
>>>> Is there a perl / linux way of locking a file? Not the FLOCK method
>>>> when you open a file, but setting the actual file as read only, or
>>>> read / write?
>>> my $cnt = chmod 0755, 'foo', 'bar';
>>
>> I was hoping to avoid using permissions, but I guess there isn't a
>> simple read only - read / write attribute in linux like in DOS. Thanks
>>
>
> I'm not sure about this, but I think you'd do better locking the file
> this way:
>
> my $cnt = chmod 0444, 'foo', 'bar';
>
> Test if a file is "unlocked" this way:
>
> if (-w 'foo') {
> ... write to 'foo' ...
> }
>
> Read these:
> perldoc -f chmod
> perldoc -f -w
I don't believe there's any way to make the implied set of operations
atomic (unless you add something, like semaphores), so it looks like
you'll have a potential race condition.
--
On 08/28/2007 09:17 PM, Jim Cochrane wrote:
> On 2007-08-28, Mumia W.
>> [ code to "lock" using chmod snipped ]
> I don't believe there's any way to make the implied set of operations
> atomic (unless you add something, like semaphores), so it looks like
> you'll have a potential race condition.
>
Hmm. I didn't think about that.