Skip to content

Commit

Permalink
check for failures in rename step
Browse files Browse the repository at this point in the history
  • Loading branch information
adammoody committed Aug 29, 2020
1 parent 1370c2d commit a799cd9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/axl.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,22 +843,35 @@ static char* axl_remove_extension(char* path_with_extension, char** extra)
*
* TODO: Make the file renames multithreaded
*/
static void axl_rename_files_to_final_names(int id)
static int axl_rename_files_to_final_names(int id)
{
int rc = AXL_SUCCESS;

char* dst;
kvtree_elem* elem = NULL;
while ((elem = axl_get_next_path(id, elem, NULL, &dst))) {
/* compute and allocate original name to store in newdst */
char* extra = NULL;
char* newdst = axl_remove_extension(dst, &extra);
if (! newdst) {
/* Nothing we can do... */
AXL_ERR("Couldn't remove extension, this shouldn't happen");
free(newdst);
continue;
}
rename(dst, newdst);

/* rename from temporary to final name */
int tmp_rc = rename(dst, newdst);
if (tmp_rc != 0) {
AXL_ERR("Failed to rename file: `%s' to `%s' errno=%d %s",
dst, newdst, errno, strerror(errno)
);
rc = AXL_FAILURE;
}

free(newdst);
}

return rc;
}

/* Test if a transfer has completed
Expand Down Expand Up @@ -981,10 +994,18 @@ int AXL_Wait (int id)
}

end:
/* if we're successful, rename temporary files to final destination names */
if (rc == AXL_SUCCESS) {
axl_rename_files_to_final_names(id);
rc = axl_rename_files_to_final_names(id);
}

/* if anything failed, be sure to mark transfer status as being in error */
if (rc != AXL_SUCCESS) {
kvtree_util_set_int(file_list, AXL_KEY_STATUS, AXL_STATUS_ERROR);
}

/* TODO: if error, delete destination files including temporaries? */

kvtree_util_set_int(file_list, AXL_KEY_STATE, (int)AXL_XFER_STATE_COMPLETED);

/* write data to file if we have one */
Expand Down

0 comments on commit a799cd9

Please sign in to comment.