New API call iso_nowtime()

This commit is contained in:
Thomas Schmitt 2019-04-18 10:56:01 +02:00
parent 4b21386e82
commit 458ab43ecd
7 changed files with 55 additions and 7 deletions

View File

@ -2418,7 +2418,7 @@ void ecma119_determine_now_time(Ecma119Image *target)
uint8_t time_text[18]; uint8_t time_text[18];
int i; int i;
t0 = time(NULL); iso_nowtime(&t0, 0);
o = target->opts; o = target->opts;
if (o->vol_uuid[0]) { if (o->vol_uuid[0]) {
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)

View File

@ -312,7 +312,7 @@ int iso_tree_add_boot_node(IsoDir *parent, const char *name, IsoBoot **boot)
node->node.hidden = parent->node.hidden; node->node.hidden = parent->node.hidden;
/* current time */ /* current time */
now = time(NULL); iso_nowtime(&now, 0);
node->node.atime = now; node->node.atime = now;
node->node.ctime = now; node->node.ctime = now;
node->node.mtime = now; node->node.mtime = now;

View File

@ -1251,6 +1251,27 @@ int iso_set_local_charset(char *name, int flag);
*/ */
char *iso_get_local_charset(int flag); char *iso_get_local_charset(int flag);
/**
* Inquire and maybe define the time which is considered to be "now" and
* used for timestamps of freshly created ISO nodes and as default of
* image timestamps.
* If ever, this should normally be enabled and defined before iso_image_new().
* If it is disabled, time(NULL) is considered to be "now".
*
* @param now
* Returns the "now" value and maybe submits it as definition.
* @param flag
* Bitfield for control purposes
* bit0= *now contains the time to be set as nowtime override.
Enable the override if not bit1 is set, too.
* bit1= Disable the nowtime override
* @return 1= *now is not overridden , 2= *now is overridden
*
* @since 1.5.2
*/
int iso_nowtime(time_t *now, int flag);
/** /**
* Create a new image, empty. * Create a new image, empty.
* *

View File

@ -226,6 +226,7 @@ iso_node_unref;
iso_node_xinfo_get_cloner; iso_node_xinfo_get_cloner;
iso_node_xinfo_make_clonable; iso_node_xinfo_make_clonable;
iso_node_zf_by_magic; iso_node_zf_by_magic;
iso_nowtime;
iso_obtain_msgs; iso_obtain_msgs;
iso_read_image_features_destroy; iso_read_image_features_destroy;
iso_read_image_features_get_size; iso_read_image_features_get_size;

View File

@ -1460,6 +1460,7 @@ void iso_notify_dir_iters(IsoNode *node, int flag)
int iso_node_new_root(IsoDir **root) int iso_node_new_root(IsoDir **root)
{ {
IsoDir *dir; IsoDir *dir;
time_t now;
dir = calloc(1, sizeof(IsoDir)); dir = calloc(1, sizeof(IsoDir));
if (dir == NULL) { if (dir == NULL) {
@ -1467,7 +1468,8 @@ int iso_node_new_root(IsoDir **root)
} }
dir->node.refcount = 1; dir->node.refcount = 1;
dir->node.type = LIBISO_DIR; dir->node.type = LIBISO_DIR;
dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL); iso_nowtime(&now, 0);
dir->node.atime = dir->node.ctime = dir->node.mtime = now;
dir->node.mode = S_IFDIR | 0555; dir->node.mode = S_IFDIR | 0555;
/* set parent to itself, to prevent root to be added to another dir */ /* set parent to itself, to prevent root to be added to another dir */

View File

@ -87,7 +87,7 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir)
iso_node_set_hidden((IsoNode*)node, parent->node.hidden); iso_node_set_hidden((IsoNode*)node, parent->node.hidden);
/* current time */ /* current time */
now = time(NULL); iso_nowtime(&now, 0);
iso_node_set_atime((IsoNode*)node, now); iso_node_set_atime((IsoNode*)node, now);
iso_node_set_ctime((IsoNode*)node, now); iso_node_set_ctime((IsoNode*)node, now);
iso_node_set_mtime((IsoNode*)node, now); iso_node_set_mtime((IsoNode*)node, now);
@ -175,7 +175,7 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
iso_node_set_hidden((IsoNode*)node, parent->node.hidden); iso_node_set_hidden((IsoNode*)node, parent->node.hidden);
/* current time */ /* current time */
now = time(NULL); iso_nowtime(&now, 0);
iso_node_set_atime((IsoNode*)node, now); iso_node_set_atime((IsoNode*)node, now);
iso_node_set_ctime((IsoNode*)node, now); iso_node_set_ctime((IsoNode*)node, now);
iso_node_set_mtime((IsoNode*)node, now); iso_node_set_mtime((IsoNode*)node, now);
@ -278,7 +278,7 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
iso_node_set_hidden((IsoNode*)node, parent->node.hidden); iso_node_set_hidden((IsoNode*)node, parent->node.hidden);
/* current time */ /* current time */
now = time(NULL); iso_nowtime(&now, 0);
iso_node_set_atime((IsoNode*)node, now); iso_node_set_atime((IsoNode*)node, now);
iso_node_set_ctime((IsoNode*)node, now); iso_node_set_ctime((IsoNode*)node, now);
iso_node_set_mtime((IsoNode*)node, now); iso_node_set_mtime((IsoNode*)node, now);
@ -367,7 +367,7 @@ int iso_tree_add_new_file(IsoDir *parent, const char *name, IsoStream *stream,
iso_node_set_hidden((IsoNode*)node, parent->node.hidden); iso_node_set_hidden((IsoNode*)node, parent->node.hidden);
/* current time */ /* current time */
now = time(NULL); iso_nowtime(&now, 0);
iso_node_set_atime((IsoNode*)node, now); iso_node_set_atime((IsoNode*)node, now);
iso_node_set_ctime((IsoNode*)node, now); iso_node_set_ctime((IsoNode*)node, now);
iso_node_set_mtime((IsoNode*)node, now); iso_node_set_mtime((IsoNode*)node, now);

View File

@ -2456,3 +2456,27 @@ int iso_truncate_leaf_name(int mode, int length, char *name, int flag)
return ret; return ret;
} }
/* API */
/* @param flag bit0= *now contains the time to be set as nowtime override
bit1= disable the nowtime override
@return 1= *now is not overridden , 2= *now is overridden
*/
int iso_nowtime(time_t *now, int flag)
{
static int now_time_overridden = 0;
static time_t now_time_override = 0;
if (flag & 1) {
now_time_overridden = 1;
now_time_override = *now;
}
if (flag & 2) {
now_time_overridden = 0;
}
*now = time(NULL);
if (!now_time_overridden)
return 1;
*now = now_time_override;
return 2;
}