Operating System - OpenVMS
1832800 Members
2841 Online
110045 Solutions
New Discussion

Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

 
SOLVED
Go to solution
Art Wiens
Respected Contributor

Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

I want to assign the result of this lexical function to a symbol and then test to see if I can proceed with some further file processing.

In my testing, if the file is "locked" (I have it OPEN/APPEND in another session), the symbol assignment blows up:

$ FILE_TO_SEND = F$SEARCH("sys$sysdevice:[mydir.temp]*.*;*",1)
$ FLOCK = F$FILE_ATTRIBUTES(FILE_TO_SEND,"LOCKED")
%SYSTEM-W-ACCONFLICT, file access conflict
\SYS$SYSDEVICE:[MYDIR.TEMP]JAN17_A.TXT;1\
$ show sym flock
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
$ IF FLOCK THEN GOTO LOCKED_EXIT
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
\FLOCK\

If I do this without the file being accessed, it's fine and the symbol FLOCK is "FALSE".

I imagine there's a different way to do this?

Cheers,
Art
19 REPLIES 19
Robert Gezelter
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Art,

I am about to run for a meeting, but you should be able to perform the needed experiment.

Having dealt with the lock bit since the days of RSX-11D, I will theorize that the lexical you need to check the underlying RMS manual for the exact meaning of the lock bit.

I will try to get a chance to take a look later.

- Bob Gezelter, http://www.rlgsc.com
Jim_McKinney
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

I suspect that "LOCKED" may not mean what you think, though it probably is adequate for what you're trying to do. Deaccess-"LOCKED" is not the same as open by another user or other usage conflict. My recollection is that it's a holdover from RSX emulation whereby a file was left in this state if improperly closed.

Anyway, this will most likely do what you require; as would F$FILE using most any argument.

$ FILE_TO_SEND = F$SEARCH("sys$sysdevice:[mydir.temp]*.*;*",1)
$ SEVERITY = F$ENVI("ON_SEVERITY")
$ ON WARNING THEN GOTO LOCKED_EXIT
$ FLOCK = F$FILE_ATTRIBUTES(FILE_TO_SEND,"LOCKED")
$ ON 'SEVERITY' THEN EXIT

You can surround the lexical invocation with redefiniton of SYS$ERROR and SYS$OUTPUT to the NL device if you want to suppress the error messages that result from the file access conflict.
Jim_McKinney
Honored Contributor
Solution

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

You might also accomplish this using the following

$ FILE_TO_SEND = F$SEARCH("sys$sysdevice:[mydir.temp]*.*;*",1)
$ OPEN/READ/WRITE/ERROR=LOCKED_EXIT FILE 'FILE_TO_SEND'
$ CLOSE FILE
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Yeh, I saw the "deaccessed lock" description and wondered why it was stated like that.

Maybe I should explain what I'm trying to solve ... it's a "typical" drop box kind of setup. What I've seen in the past is that the during the act of a file being written to the drop directory, my procedure looks in every few minutes and "finds" the file. If the remote process is not finished writing it, I can't work with it (RMS-E-FLK). I handle it, but after the fact. I want to try and make sure that it's available before I carry on hence the desire to see if it's "locked" first.

Cheers,
Art
Robert Brooks_1
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

The standard way of dealing with this potential race condition is to have the file created with a different name, and then renamed to the expected name after the transfer is complete.

-- Rob
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Trouble is, the incoming file could be one of say 15 different variations, I never know what to expect. In fact what I'm trying to enhance in my existing procedure is renaming the file once I find it.

Art
Arch_Muthiah
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Art,

could you able to change your open/append command with
$OPEN/APPEND/SHARE

Archunan
Regards
Archie
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

The OPEN/APPEND in another session I mentioned was a meager manual attempt to reproduce the contention I might get "for real".

The real drop into the folder is a Decnet copy, I need to rename the file in preparation for FTP'ing to a 3rd party.

I need to know I have exclusive access to the file before I continue. I think the attempting to open it as my status test sounds reasonable.

Will let you know.

Cheers,
Art
Wim Van den Wyngaert
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Just hope that no one else opens the file exclusive while your doing your open. It could fail.

Wim
Wim
Daniel Fernandez Illan
Trusted Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Art
For a similar question (copy a file after his generation) I use this command file to test error if file is opened:
$set noon
$fil=f$search("*fic*")
$do:
$!Check if file is locked or opened
$att=f$file_attributes("''fil'","eof")
$if $status .eqs. "%X00000800" !File open
$then
$ wait 00:03
$ goto do
$endif

Saludos.
Daniel.
$exit
Robert Gezelter
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Art,

Ok, I am not in such a hurry at this instant.

The LOCKED bit would be on in RSX if the file was not "properly closed". Under RSX, file processing (FCS or RMS) ran in user mode (in RSX-11M-PLUS, RMS could be implemented as a Supervisor mode library, but that is not the same as the RMS implementation in OpenVMS, when an RSX image aborted, the file status was not cleaned up in any way).

This was also the behavior when the system crashed while the file was open for modification. File closing is done differently, but since I lack a machine that I can crash at my pleasure at this instant, I cannot confirm, but strongly suspect that if I have a file open at the time of a crash, I will get a similar status.

The actual file locking (on both RSX and Open VMS) is done via a totally different mechanism, RSX had no mechanism for managing cross system sharing, OpenVMS has the cluster wide locking managed by the Lock Manager.

The best way to check if a file is complete in your case is to check if you can open it for exclusive write. If the open fails, the file is not yet complete. If my memory about the LOCKED state is correct, you also need that check to guard against a file that was left in an incomplete state (and maybe some other consistency checks to guard against files where the incomming network copy was not successful).

- Bob Gezelter, http://www.rlgsc.com
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Wim: Should not be an issue. The drop box is the last leg of this file's journey before it leaves our network. It's out of the normal production areas, and I know no one else is in there.

Daniel: Thanks. I'll try and rig up a test to see if that's any "better" than trying the OPEN/WRITE test.

Bob: Thanks as well. I remember even less of RSX than I do of VMS ;-)

Cheers,
Art
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

One last thing before I put my "new and improved" procedure in production ... I ran DCL_CHECK against it and it came up with one error:

LINE CODE --DIAGNOSTIC MESSAGE--
196 UPQ unpaired quotation marks (")

The line in question is from part of the routine that WRITEs a temporary comand procedure that will do the actual FTP. I know 100% that it works, but I'm wondering if it really is a syntax problem and if so, what's the proper way.

The line is:

$ WRITE FTPCOM "$ FTP OPEN ''FTP_SITE' ''FTP_USER' ""''FTP_PASS'""

The password that was assigned by the third party vendor is case-sensitive so I need to double quote it. This line wasn't changed and has been called several thousand times in the past two years without fail.

Is it ""wrong"?
Art
Karl Rohwedder
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

It's difficult to separate " from '', but
isn't the last " mising (to close the textstring to WRITE)?

regards Kalle
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

I knew this silly little text box would make it hard to read.

"$ FTP OPEN ''FTP_SITE' ''FTP_USER' ""''FTP_PASS'""

FTP_SITE has two singles before and one single after

FTP_USER same

FTP_PASS has two double quotes, two single quotes before it and one single quote and two double quotes after it.

Basically one set of double quotes surrounding what I want to WRITE and FTP_PASS escaped with with double quotes to get it into what I want to WRITE.

I'll try an attachment and see if that's better.

Cheers,
Art
Karl Rohwedder
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

As I suggested, the last double quote is missing, the one that closes the WRITE-text.
This doesn't make any problemin DCL, because DCL just terminates the textstring when then line ends, but to be very correct...

regards Kalle

P.S. I attached my version...
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Kalle that seems "wrong" to me - one too many double quotes.

Just like you need two singles before and one single after for symbol substitution, I think it would be two doubles before and one double after to make one set of doubles appear in the overall double quoted string.

If we take symbols out of the equation for a moment and say we wanted to have a double quoted word inside the line would we not do this:

(only double quotes in the following)

$ WRITE temp "This is a ""quoted" word"

Is that not standard escaping practice?

Cheers,
Art
Hein van den Heuvel
Honored Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

WRITE temp "This is a ""quoted" word"

To make a double-quote appear in a quoted text, you need to double-up on those double quotes.
You have that correct before the word, but incorrect after.

WRITE temp "This is a ""quoted"" word"

but you probably already realized that...

Btw, the := assignment adds more fun:

$ x:=This is a "quoted" word
$ show symb x
X = "THIS IS A quoted WORD"

Hein.
Art Wiens
Respected Contributor

Re: Lexical F$FILE_ATTRIBUTES(filename,"LOCKED") usage

Ok, if Hein says so, that's the way it is!

I can only give you 9 points though because I'm not happy it doesn't work the way I think it should. ;-) Kalle, reply once more and I'll ""top you up"".

Into production we go ...

Cheers,
Art