diff --git a/dcapi/boinc/wu.C b/dcapi/boinc/wu.C index d981361e70..8567a0ff0f 100644 --- a/dcapi/boinc/wu.C +++ b/dcapi/boinc/wu.C @@ -670,8 +670,36 @@ static int check_logical_name(DC_Workunit *wu, const char *logicalFileName) return 0; } +static void create_hash_file(DC_PhysicalFile *file, const char *hashString) +{ + const char *hashFileExt=".md5"; + GString *hashFile; + FILE *f; + + if (!hashString || !file || !file->path) + return; + + hashFile = g_string_new(file->path); + g_string_append(hashFile, hashFileExt); + + f = fopen(hashFile->str, "w"); + if (!f) + { + DC_log(LOG_ERR, "Failed to create file %s: %s", hashFile->str,strerror(errno)); + g_string_free(hashFile, TRUE); + return; + } + fprintf(f, "%s", hashString); + fclose(f); + + DC_log(LOG_DEBUG, "MD5 hash file \"%s\" has been created with content \"%s\".", hashFile->str, hashString); + + g_string_free(hashFile, TRUE); + return; +} + int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, - DC_FileMode fileMode) + DC_FileMode fileMode, const char *hashString = NULL) { DC_PhysicalFile *file; char *workpath; @@ -704,6 +732,7 @@ int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, { /* Remember the file mode */ file->mode = DC_FILE_PERSISTENT; + create_hash_file(file, hashString); break; } @@ -719,12 +748,15 @@ int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, _DC_destroyPhysicalFile(file); return ret; } + create_hash_file(file, hashString); break; case DC_FILE_VOLATILE: ret = rename(URL, file->path); if (!ret) + { + create_hash_file(file, hashString); break; - + } DC_log(LOG_DEBUG, "Renaming failed for input file %s: %s; " "falling back to copy/delete", URL, strerror(errno)); ret = _DC_copyFile(URL, file->path); @@ -736,6 +768,7 @@ int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, return ret; } unlink(URL); + create_hash_file(file, hashString); break; default: DC_log(LOG_ERR, "Invalid file mode %d", fileMode); diff --git a/dcapi/include/dc.h b/dcapi/include/dc.h index 7075a6c9b3..0cedf53a49 100644 --- a/dcapi/include/dc.h +++ b/dcapi/include/dc.h @@ -147,7 +147,7 @@ DC_Workunit *DC_createWU(const char *clientName, const char *arguments[], /* Sets an input file for the work unit. */ int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, - DC_FileMode fileMode); + DC_FileMode fileMode, const char *hashString); /* Defines an output file for the work unit. */ int DC_addWUOutput(DC_Workunit *wu, const char *logicalFileName); diff --git a/dcapi/local/Makefile.am b/dcapi/local/Makefile.am index 82a7ce0870..735401cbf4 100644 --- a/dcapi/local/Makefile.am +++ b/dcapi/local/Makefile.am @@ -21,7 +21,7 @@ noinst_HEADERS = \ local_wu.h libdcapi_local_la_SOURCES = \ - local_master.c \ + local_master.C \ local_events.c \ local_result.c \ local_utils.c \ diff --git a/dcapi/local/local_master.c b/dcapi/local/local_master.C similarity index 96% rename from dcapi/local/local_master.c rename to dcapi/local/local_master.C index fcb51f590e..64aa777b82 100644 --- a/dcapi/local/local_master.c +++ b/dcapi/local/local_master.C @@ -1,14 +1,14 @@ /* - * local/local_master.c + * local/local_master.C * * DC-API functions of master side * * (c) Gabor Vida 2005-2006, Daniel Drotos, 2007 */ -/* $Id$ */ -/* $Date$ */ -/* $Revision$ */ +/* $Id: local_master.c 2246 2009-09-08 15:28:03Z gombasg $ */ +/* $Date: 2009-09-08 17:28:03 +0200 (Tue, 08 Sep 2009) $ */ +/* $Revision: 2246 $ */ #ifdef HAVE_CONFIG_H #include @@ -503,7 +503,7 @@ static int copy_file(const char *src, const char *dst) } int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL, - DC_FileMode fileMode) + DC_FileMode fileMode, const char *hashString = NULL) { DC_PhysicalFile *file; char *workpath; @@ -789,7 +789,7 @@ DC_sendWUMessage(DC_Workunit *wu, const char *message) dn= g_string_new(wu->workdir); g_string_append(dn, "/"); g_string_append(dn, _DC_wu_cfg(wu, cfg_master_message_box)); - ret= _DC_create_message(dn->str, _DCAPI_MSG_MESSAGE, message, NULL); + ret= _DC_create_message(dn->str, (char*)_DCAPI_MSG_MESSAGE, message, NULL); g_string_free(dn, TRUE); return(ret); } @@ -800,13 +800,12 @@ static struct { char *name; } _DC_state_names[]= { - { DC_WU_READY, "READY" }, - { DC_WU_RUNNING, "RUNNING" }, - { DC_WU_FINISHED, "FINISHED" }, - { DC_WU_SUSPENDED, "SUSPENDED" }, - { DC_WU_ABORTED, "ABORTED" }, - { DC_WU_UNKNOWN, "UNKNOWN" }, - { 0, NULL } + { DC_WU_READY, (char*) "READY" }, + { DC_WU_RUNNING, (char*) "RUNNING" }, + { DC_WU_FINISHED, (char*) "FINISHED" }, + { DC_WU_SUSPENDED, (char*) "SUSPENDED" }, + { DC_WU_ABORTED, (char*) "ABORTED" }, + { DC_WU_UNKNOWN, (char*) "UNKNOWN" } }; char * @@ -815,8 +814,8 @@ _DC_state_name(DC_WUState state) int i; for (i= 0; _DC_state_names[i].name; i++) if (_DC_state_names[i].state == state) - return(_DC_state_names[i].name); - return("(unknown)"); + return _DC_state_names[i].name; + return _DC_state_names[DC_WU_UNKNOWN].name; }