Author: hbelusca Date: Wed Jan 28 20:26:56 2015 New Revision: 66100
URL: http://svn.reactos.org/svn/reactos?rev=66100&view=rev Log: [CDMAKE] - 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.
Modified: trunk/reactos/tools/cdmake/cdmake.c trunk/reactos/tools/cdmake/dirhash.c trunk/reactos/tools/cdmake/dirhash.h
Modified: trunk/reactos/tools/cdmake/cdmake.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/cdmake.c?rev=6... ============================================================================== --- trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] Wed Jan 28 20:26:56 2015 @@ -503,8 +503,7 @@ 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 @@
#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_time_string(char *str) { - struct tm *current; - time_t timestamp = time(NULL); - current = gmtime(×tamp); 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 @@
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 @@ error_exit("Insufficient memory");
memset(&root, 0, sizeof(root)); - current_time = gmtime(×tamp); 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, ×tamp);
// initialize CD-ROM write buffer
Modified: trunk/reactos/tools/cdmake/dirhash.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/dirhash.c?rev=... ============================================================================== --- trunk/reactos/tools/cdmake/dirhash.c [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/dirhash.c [iso-8859-1] Wed Jan 28 20:26:56 2015 @@ -59,21 +59,19 @@ 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) -{ - unsigned int hashcode; +delete_entry(struct target_dir_hash *dh, struct target_dir_entry *de) +{ 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 @@ 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 @@ 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 @@ 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 @@ 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); }
Modified: trunk/reactos/tools/cdmake/dirhash.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/dirhash.h?rev=... ============================================================================== --- trunk/reactos/tools/cdmake/dirhash.h [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/dirhash.h [iso-8859-1] Wed Jan 28 20:26:56 2015 @@ -12,6 +12,9 @@
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_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 *