Skip to content

Commit

Permalink
Warn when a file rename fails while renaming a vm.
Browse files Browse the repository at this point in the history
This is a "minimum effort" warning.
Multiple files are being renamed.
When a vm file is not renamed correctly then the vm will be in an unknown state.
The user will need to fix the filenames manually.
  • Loading branch information
flaviojs committed Mar 23, 2024
1 parent 37e438f commit b2f5634
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion stable/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,9 @@ int vm_rename_instance(vm_instance_t *vm, char *name)
if ((filename = dyn_sprintf("%s_%s_%s",vm_get_type(vm),vm->name,globbuf.gl_pathv[i] + strlen(pattern) - 1)) == NULL)
break; /* out of memory */

rename(globbuf.gl_pathv[i], filename);
if (rename(globbuf.gl_pathv[i], filename) != 0) {
fprintf(stderr, "Warning: vm_rename_instance: rename(\"%s\",\"%s\"): %s\n", globbuf.gl_pathv[i], filename, strerror(errno));
}
free(filename);
}
globfree(&globbuf);
Expand Down
4 changes: 3 additions & 1 deletion unstable/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,9 @@ int vm_rename_instance(vm_instance_t *vm, char *name)
if ((filename = dyn_sprintf("%s_%s_%s",vm_get_type(vm),vm->name,globbuf.gl_pathv[i] + strlen(pattern) - 1)) == NULL)
break; /* out of memory */

rename(globbuf.gl_pathv[i], filename);
if (rename(globbuf.gl_pathv[i], filename) != 0) {
fprintf(stderr, "Warning: vm_rename_instance: rename(\"%s\",\"%s\"): %s\n", globbuf.gl_pathv[i], filename, strerror(errno));
}
free(filename);
}
globfree(&globbuf);
Expand Down

0 comments on commit b2f5634

Please sign in to comment.