Add explicit :TRUNCATE option for :IF-EXISTS in OPEN

In the future we may want to make :SUPERSEDE transaction-like.
This commit is contained in:
Daniel Kochmanski 2018-05-06 08:20:54 +02:00
parent 2fa20297b3
commit d9c4b2a88c
4 changed files with 11 additions and 4 deletions

View file

@ -5107,7 +5107,12 @@ ecl_open_stream(cl_object fn, enum ecl_smmode smm, cl_object if_exists,
unlikely_if (f < 0) FEcannot_open(fn);
} else if (if_exists == @':rename_and_delete' ||
if_exists == @':new_version' ||
if_exists == @':supersede') {
/* :SUPERSEDE could write to a new file and only upon succesful
close it could replace the file in question. That way we'd
assure a transaction-like behavior. We add :TRUNACTE for
explicit truncate action. */
if_exists == @':supersede' ||
if_exists == @':truncate') {
f = safe_open(fname, base|O_TRUNC, mode);
unlikely_if (f < 0) FEcannot_open(fn);
} else if (if_exists == @':overwrite' || if_exists == @':append') {

View file

@ -1435,6 +1435,7 @@ cl_symbols[] = {
{KEY_ "TAG", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "TEST", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "TEST-NOT", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "TRUNCATE", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "TYPE", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "UNSPECIFIC", KEYWORD, NULL, -1, OBJNULL},
{KEY_ "UNMASK", KEYWORD, NULL, -1, OBJNULL},

View file

@ -1435,6 +1435,7 @@ cl_symbols[] = {
{KEY_ "TAG",NULL},
{KEY_ "TEST",NULL},
{KEY_ "TEST-NOT",NULL},
{KEY_ "TRUNCATE",NULL},
{KEY_ "TYPE",NULL},
{KEY_ "UNSPECIFIC",NULL},
{KEY_ "UNMASK",NULL},

View file

@ -2263,9 +2263,9 @@ FILESPEC may be a symbol, a string, a pathname, or a file stream.
DIRECTION may be :INPUT, :OUTPUT, :IO, or :PROBE.
IF-EXISTS specifies what to do when DIRECTION is either :OUTPUT or :IO
and the specified file exists already. It may be :ERROR (the
default), :NEW-VERSION, :RENAME, :RENAME-AND-DELETE, :OVERWRITE, :APPEND,
IF-EXISTS specifies what to do when DIRECTION is either :OUTPUT or :IO and the
specified file exists already. It may be :ERROR (the
default), :NEW-VERSION, :RENAME, :RENAME-AND-DELETE, :OVERWRITE, :APPEND, :TRUNCATE
:SUPERSEDE, or NIL.
IF-DOES-NOT-EXIST specifies what to do when the specified file does