/* for file name listed in meta, fetch that file from src_dir and store * a copy in dst_dir, record full path to copy in newfile, and * return whether operation succeeded */ static int scr_fetch_file( const char* dst_file, const char* src_dir, const scr_meta* meta) { int rc = SCR_SUCCESS; /* build full path to source file */ scr_path* path_src_file = scr_path_from_str(dst_file); scr_path_basename(path_src_file); scr_path_prepend_str(path_src_file, src_dir); char* src_file = scr_path_strdup(path_src_file); /* fetch the file */ uLong crc; uLong* crc_p = NULL; if (scr_crc_on_flush) { crc_p = &crc; } rc = scr_file_copy(src_file, dst_file, scr_file_buf_size, crc_p); /* check that crc matches crc stored in meta */ uLong meta_crc; if (scr_meta_get_crc32(meta, &meta_crc) == SCR_SUCCESS) { if (rc == SCR_SUCCESS && scr_crc_on_flush && crc != meta_crc) { rc = SCR_FAILURE; scr_err("CRC32 mismatch detected when fetching file from %s to %s @ %s:%d", src_file, dst_file, __FILE__, __LINE__ ); /* TODO: would be good to log this, but right now only rank 0 * can write log entries */ /* if (scr_log_enable) { time_t now = scr_log_seconds(); scr_log_event("CRC32 MISMATCH", filename, NULL, &now, NULL); } */ } } /* free path and string for source file */ scr_free(&src_file); scr_path_delete(&path_src_file); return rc; }
/* flushes file named in src_file to dst_dir and fills in meta based on flush, * returns success of flush */ static int scr_flush_a_file(const char* src_file, const char* dst_dir, scr_meta* meta) { int flushed = SCR_SUCCESS; int tmp_rc; /* build full name to destination file */ scr_path* dst_path = scr_path_from_str(src_file); scr_path_basename(dst_path); scr_path_prepend_str(dst_path, dst_dir); scr_path_reduce(dst_path); char* dst_file = scr_path_strdup(dst_path); /* copy file */ int crc_valid = 0; uLong crc; uLong* crc_p = NULL; if (scr_crc_on_flush) { crc_valid = 1; crc_p = &crc; } tmp_rc = scr_file_copy(src_file, dst_file, scr_file_buf_size, crc_p); if (tmp_rc != SCR_SUCCESS) { crc_valid = 0; flushed = SCR_FAILURE; } scr_dbg(2, "scr_flush_a_file: Read and copied %s to %s with success code %d @ %s:%d", src_file, dst_file, tmp_rc, __FILE__, __LINE__ ); /* if file has crc32, check it against the one computed during the copy, * otherwise if scr_crc_on_flush is set, record crc32 */ if (crc_valid) { uLong crc_meta; if (scr_meta_get_crc32(meta, &crc_meta) == SCR_SUCCESS) { if (crc != crc_meta) { /* detected a crc mismatch during the copy */ /* TODO: unlink the copied file */ /* scr_file_unlink(dst_file); */ /* mark the file as invalid */ scr_meta_set_complete(meta, 0); flushed = SCR_FAILURE; scr_err("scr_flush_a_file: CRC32 mismatch detected when flushing file %s to %s @ %s:%d", src_file, dst_file, __FILE__, __LINE__ ); /* TODO: would be good to log this, but right now only rank 0 can write log entries */ /* if (scr_log_enable) { time_t now = scr_log_seconds(); scr_log_event("CRC32 MISMATCH", dst_file, NULL, &now, NULL); } */ } } else { /* the crc was not already in the metafile, but we just computed it, so set it */ scr_meta_set_crc32(meta, crc); } } /* TODO: check that written filesize matches expected filesize */ /* fill out meta data, set complete field based on flush success */ /* (we don't update the meta file here, since perhaps the file in cache is ok and only the flush failed) */ int complete = (flushed == SCR_SUCCESS); scr_meta_set_complete(meta, complete); /* free destination file string and path */ scr_free(&dst_file); scr_path_delete(&dst_path); return flushed; }