- Fix misusage of the hash-table. CORE-9098 #resolve #comment Fixed in revision 66100!
- Really fix date for files and directories when CDs are generated on Windows. Use UTC time everywhere. Simplify code.

svn path=/trunk/; revision=66100
This commit is contained in:
Hermès Bélusca-Maïto
2015-01-28 20:26:56 +00:00
parent 311d5df6e2
commit abc4e17f7c
3 changed files with 41 additions and 81 deletions
+14 -23
View File
@@ -503,8 +503,7 @@ puts them into a date_and_time structure.
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
{
struct tm *timedef;
timedef = localtime(time);
timedef = gmtime(time);
dt->second = timedef->tm_sec;
dt->minute = timedef->tm_min;
@@ -1089,22 +1088,24 @@ new_empty_dirrecord(PDIR_RECORD d, BOOL directory)
#if _WIN32
static int
get_cd_file_time(HANDLE handle, DATE_AND_TIME *cd_time_info)
get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info)
{
FILETIME file_time;
SYSTEMTIME sys_time;
if (!GetFileTime(handle, NULL, NULL, &file_time))
{
return -1;
}
FileTimeToSystemTime(&file_time, &sys_time);
memset(cd_time_info, 0, sizeof(*cd_time_info));
cd_time_info->year = sys_time.wYear;
cd_time_info->month = sys_time.wMonth - 1;
cd_time_info->month = sys_time.wMonth;
cd_time_info->day = sys_time.wDay;
cd_time_info->hour = sys_time.wHour;
cd_time_info->minute = sys_time.wMinute;
cd_time_info->second = sys_time.wSecond;
return 0;
}
#endif
@@ -1250,16 +1251,13 @@ static void get_file_specifications(PDIR_RECORD d)
static void get_time_string(char *str)
{
struct tm *current;
time_t timestamp = time(NULL);
current = gmtime(&timestamp);
sprintf(str, "%04d%02d%02d%02d%02d%02d00",
current->tm_year + 1900,
current->tm_mon,
current->tm_mday,
current->tm_hour,
current->tm_min,
current->tm_sec);
root.date_and_time.year,
root.date_and_time.month,
root.date_and_time.day,
root.date_and_time.hour,
root.date_and_time.minute,
root.date_and_time.second);
}
static void pass(void)
@@ -1676,7 +1674,6 @@ Program execution starts here.
int main(int argc, char **argv)
{
struct tm *current_time;
time_t timestamp = time(NULL);
BOOL q_option = FALSE;
BOOL v_option = FALSE;
@@ -1699,15 +1696,9 @@ int main(int argc, char **argv)
error_exit("Insufficient memory");
memset(&root, 0, sizeof(root));
current_time = gmtime(&timestamp);
root.level = 1;
root.flags = DIRECTORY_FLAG;
root.date_and_time.year = current_time->tm_year + 1900;
root.date_and_time.month = current_time->tm_mon + 1;
root.date_and_time.day = current_time->tm_mday;
root.date_and_time.hour = current_time->tm_hour;
root.date_and_time.minute = current_time->tm_min;
root.date_and_time.second = current_time->tm_sec;
convert_date_and_time(&root.date_and_time, &timestamp);
// initialize CD-ROM write buffer
+24 -50
View File
@@ -59,21 +59,19 @@ get_entry_by_normname(struct target_dir_hash *dh, const char *norm)
hashcode = djb_hash(norm);
de = dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS];
while (de && strcmp(de->normalized_name, norm))
de = de->next;
de = de->next_dir_hash_entry;
return de;
}
static void
delete_entry_by_normname(struct target_dir_hash *dh, const char *norm)
delete_entry(struct target_dir_hash *dh, struct target_dir_entry *de)
{
unsigned int hashcode;
struct target_dir_entry **ent;
hashcode = djb_hash(norm);
ent = &dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS];
while (*ent && strcmp((*ent)->normalized_name, norm))
ent = &(*ent)->next;
ent = &dh->buckets[de->hashcode % NUM_DIR_HASH_BUCKETS];
while (*ent && ((*ent) != de))
ent = &(*ent)->next_dir_hash_entry;
if (*ent)
*ent = (*ent)->next;
*ent = (*ent)->next_dir_hash_entry;
}
void normalize_dirname(char *filename)
@@ -115,41 +113,47 @@ void normalize_dirname(char *filename)
struct target_dir_entry *
dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm)
{
unsigned int hashcode;
struct target_dir_entry *de, *parent_de;
char *parentname = NULL;
char *parentcase = NULL;
struct target_dir_entry **ent;
if (!dh->root.normalized_name)
{
dh->root.normalized_name = strdup("");
dh->root.case_name = strdup("");
hashcode = djb_hash("");
dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS] = &dh->root;
dh->root.hashcode = djb_hash("");
dh->buckets[dh->root.hashcode % NUM_DIR_HASH_BUCKETS] = &dh->root;
}
de = get_entry_by_normname(dh, targetnorm);
if (de)
return de;
chop_dirname(targetnorm, &parentname);
chop_dirname(casename, &parentcase);
parent_de = dir_hash_create_dir(dh, parentcase, parentname);
free(parentname);
free(parentcase);
hashcode = djb_hash(targetnorm);
de = calloc(1, sizeof(*de));
de->parent = parent_de;
de->head = NULL;
de->child = NULL;
de->parent = parent_de;
de->normalized_name = strdup(targetnorm);
de->case_name = strdup(chop_filename(casename));
de->hashcode = djb_hash(targetnorm);
de->next = parent_de->child;
parent_de->child = de;
ent = &dh->buckets[hashcode % NUM_DIR_HASH_BUCKETS];
ent = &dh->buckets[de->hashcode % NUM_DIR_HASH_BUCKETS];
while (*ent)
{
ent = &(*ent)->next;
ent = &(*ent)->next_dir_hash_entry;
}
*ent = de;
return de;
}
@@ -159,12 +163,14 @@ void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const cha
struct target_dir_entry *de;
char *targetdir = NULL;
char *targetnorm;
chop_dirname(target, &targetdir);
targetnorm = strdup(targetdir);
normalize_dirname(targetnorm);
de = dir_hash_create_dir(dh, targetdir, targetnorm);
free(targetnorm);
free(targetdir);
tf = calloc(1, sizeof(*tf));
tf->next = de->head;
de->head = tf;
@@ -172,44 +178,12 @@ void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const cha
tf->target_name = strdup(chop_filename(target));
}
#if 0
static struct target_dir_entry *
dir_hash_next_dir(struct target_dir_hash *dh, struct target_dir_traversal *t)
{
if (t->i == -1)
return NULL;
if (!t->it)
{
while (++t->i != NUM_DIR_HASH_BUCKETS)
{
if (dh->buckets[t->i])
{
t->it = dh->buckets[t->i];
return t->it;
}
}
t->i = -1;
return NULL;
}
else
{
t->it = t->it->next;
if (!t->it)
{
t->i = -1;
return NULL;
}
else
return t->it;
}
}
#endif
static void
dir_hash_destroy_dir(struct target_dir_hash *dh, struct target_dir_entry *de)
{
struct target_file *tf;
struct target_dir_entry *te;
while ((te = de->child))
{
de->child = te->next;
@@ -223,8 +197,8 @@ dir_hash_destroy_dir(struct target_dir_hash *dh, struct target_dir_entry *de)
free(tf->target_name);
free(tf);
}
if (de->normalized_name)
delete_entry_by_normname(dh, de->normalized_name);
delete_entry(dh, de);
free(de->normalized_name);
free(de->case_name);
}
+3 -8
View File
@@ -12,6 +12,9 @@ struct target_file
struct target_dir_entry
{
unsigned int hashcode;
struct target_dir_entry *next_dir_hash_entry;
struct target_dir_entry *next;
struct target_dir_entry *parent;
struct target_dir_entry *child;
@@ -26,14 +29,6 @@ struct target_dir_hash
struct target_dir_entry root;
};
#if 0
struct target_dir_traversal
{
struct target_dir_entry *it;
int i;
};
#endif
void normalize_dirname(char *filename);
void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target);
struct target_dir_entry *