diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 0b6aa61..1d913ce 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -2418,7 +2418,7 @@ void ecma119_determine_now_time(Ecma119Image *target) uint8_t time_text[18]; int i; - t0 = time(NULL); + iso_nowtime(&t0, 0); o = target->opts; if (o->vol_uuid[0]) { for(i = 0; i < 16; i++) diff --git a/libisofs/eltorito.c b/libisofs/eltorito.c index ba220b0..39a3137 100644 --- a/libisofs/eltorito.c +++ b/libisofs/eltorito.c @@ -312,7 +312,7 @@ int iso_tree_add_boot_node(IsoDir *parent, const char *name, IsoBoot **boot) node->node.hidden = parent->node.hidden; /* current time */ - now = time(NULL); + iso_nowtime(&now, 0); node->node.atime = now; node->node.ctime = now; node->node.mtime = now; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 030e4c1..9dcb3d5 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -1251,6 +1251,27 @@ int iso_set_local_charset(char *name, 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. * diff --git a/libisofs/libisofs.ver b/libisofs/libisofs.ver index 70cd2c2..72f9c6d 100644 --- a/libisofs/libisofs.ver +++ b/libisofs/libisofs.ver @@ -226,6 +226,7 @@ iso_node_unref; iso_node_xinfo_get_cloner; iso_node_xinfo_make_clonable; iso_node_zf_by_magic; +iso_nowtime; iso_obtain_msgs; iso_read_image_features_destroy; iso_read_image_features_get_size; diff --git a/libisofs/node.c b/libisofs/node.c index 393ddc7..12ad939 100644 --- a/libisofs/node.c +++ b/libisofs/node.c @@ -1460,6 +1460,7 @@ void iso_notify_dir_iters(IsoNode *node, int flag) int iso_node_new_root(IsoDir **root) { IsoDir *dir; + time_t now; dir = calloc(1, sizeof(IsoDir)); if (dir == NULL) { @@ -1467,7 +1468,8 @@ int iso_node_new_root(IsoDir **root) } dir->node.refcount = 1; 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; /* set parent to itself, to prevent root to be added to another dir */ diff --git a/libisofs/tree.c b/libisofs/tree.c index c392679..12411da 100644 --- a/libisofs/tree.c +++ b/libisofs/tree.c @@ -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); /* current time */ - now = time(NULL); + iso_nowtime(&now, 0); iso_node_set_atime((IsoNode*)node, now); iso_node_set_ctime((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); /* current time */ - now = time(NULL); + iso_nowtime(&now, 0); iso_node_set_atime((IsoNode*)node, now); iso_node_set_ctime((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); /* current time */ - now = time(NULL); + iso_nowtime(&now, 0); iso_node_set_atime((IsoNode*)node, now); iso_node_set_ctime((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); /* current time */ - now = time(NULL); + iso_nowtime(&now, 0); iso_node_set_atime((IsoNode*)node, now); iso_node_set_ctime((IsoNode*)node, now); iso_node_set_mtime((IsoNode*)node, now); diff --git a/libisofs/util.c b/libisofs/util.c index ac6791f..7ab0d8b 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -2456,3 +2456,27 @@ int iso_truncate_leaf_name(int mode, int length, char *name, int flag) 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; +} +