· Oct 13, 2020

replicate file versioning of VMS in UNIX

Hi team

We are migrating the Code set of VMS to Unix. 
In this process we are also taking care of all I/O operations of file. 
In VMS, whenever we create a file, it generates a Version # associated with the file. Best part is we have a common library which we use to OPEN/USE/CLOSE/DELETE/RENAME/COPY the file.
Now, when we talk about VMS on cache, if we two processes creates a file "ABC.TXT", for 1st process it will create the version #1 and for second it will create #2.
This versioning cache handles internally, like which cache process is referring to #1 and which one for #2

Can someone help me to understand how cache handles / deal in such scenarios, like which process is referring to which number, as we are not modifying the filename when we issue USE / CLOSE command, it is cache process which internally take care of it ? 

Thanks in Advance

Paras Batheja

Discussion (4)3
Log in or sign up to continue

Hello Paras,

to understand the way Caché distinguishes between the files, you can use the special variable $ZIO. This returns the full filename.

If you run this example in two separate terminal sessions then you see, that the version number is incremented. When you do this in the same terminal session and don't close the file then the version number is NOT incremented. The fileversion will be incremented, when the file has been closed (... USE FILE SET FULLFILE=$ZIO CLOSE FILE OPEN FILE:"N" USE FILE SET FULLFILE=$ZIO...).
When you check the content of FULLFILE you'll find the full filename including the version number.

When another process does the same, another file handle is created and if you check $ZIO then you'll see, that this process is using another file version.

Hello Peter.

Thank you for the reply. 

Now, I have another question w.r.t your reply.

Thing is we are migrating our system from VMS to linux, and we are looking a wayout how to create automatic versions in UNIX ( like $ZIO does ). Something like below :

1. User creates a file "ABC.TXT" 

2. Our custom library will create a file "ABC_1.TXT"

3. then we will set the $ZIO to ABC_1.txt, like this. or any thing equivalent to $ZIO which can set the reference of the DEV in the memory ( like which file to hit ) 

Any comments / suggestions / advise ..


Hello Paras,

you can't modify $ZIO. When you create a file ABC_1.txt, $ZIO points to this file. When you create a file ABC_2.txt then $ZIO points to this file. Because Unix doesn't know version numbers, you must implement your own file version counter into your  library.
We were confronted with the same problem. We solved it by checking the existing files (doing a directory listing into a local array) estimate the highest version number and incremented 1 to that number. After getting the latest file version number we create the filename. We wrote a wrapper around the class %Library.File.

I know, that it is not perfect to browse the current directory to find all files and extract the version number out of a part of the filename. But I didn't find a better solution.

Best regards

Paras, On OpenVMS, versioning is handled by RMS services; the versioning is supported by the filesystem.  That versioning doesn't exist on Linux.  In %Library.File these might help (or might help Hans-Peter, too):

GetFileDateCreated() -> gives creation date to the second in $H format, given the filename.

GetFileDateModified() -> last-modified time in $H format, again given the name.

And the FileSet query might help browsing the directory, too:

query FileSet(directory As %String(MAXLEN=""), wildcards As %String, sortby As %String = "", includedirs As %Boolean = 0, delimiter As %String = ";")