diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 7be3fd18f80..ed79a9e260e 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -2089,20 +2089,38 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data) return -1; } - if (BKE_blendfile_extension_check(filepath)) { - /* Just pretend a file was loaded, so the user can press Save and it'll - * save at the filepath from the CLI. */ - STRNCPY(G_MAIN->filepath, filepath); - printf("... opened default scene instead; saving will write to: %s\n", filepath); + const char *error_msg = NULL; + if (BLI_exists(filepath)) { + /* When a file is found but can't be loaded, handling it as a new file + * could cause it to be unintentionally overwritten (data loss). + * Further this is almost certainly not that a user would expect or want. + * If they do, they can delete the file beforehand. */ + error_msg = "file could not be loaded"; } - else { - fprintf( - stderr, - "Error: argument has no '.blend' file extension, not using as new file, exiting! %s\n", - filepath); + else if (!BKE_blendfile_extension_check(filepath)) { + /* Unrelated arguments should not be treated as new blend files. */ + error_msg = "argument has no '.blend' file extension, not using as new file"; + } + + if (error_msg) { + fprintf(stderr, "Error: %s, exiting! %s\n", error_msg, filepath); + G.is_break = true; WM_exit(C); + /* Unreachable, return for clarity. */ + return -1; } + + /* Behave as if a file was loaded, calling "Save" will write to the `filepath` from the CLI. + * + * WARNING: The path referenced may be incorrect, no attempt is made to validate the path + * here or check that writing to it will work. If the users enters the path of a directory + * that doesn't exist (for e.g.) saving will fail. + * Attempting to create the file at this point is possible but likely to cause more + * trouble than it's worth (what with network drives), removable devices ... etc. */ + + STRNCPY(G_MAIN->filepath, filepath); + printf("... opened default scene instead; saving will write to: %s\n", filepath); } return 0;