mirror of https://gitee.com/openkylin/libvirt.git
virfile: Check for existence of dir in virFileDeleteTree
Commit id 'f1f68ca33' added code to remove the directory paths for auto-generated sockets, but that code could be called before the paths were created resulting in generating error messages from virFileDeleteTree indicating that the file doesn't exist. Rather than "enforce" all callers to make the non-NULL and existence checks, modify the virFileDeleteTree API to silently ignore NULL on input and non-existent directory trees.
This commit is contained in:
parent
41d4104d3e
commit
b421a70811
|
@ -5269,13 +5269,11 @@ void qemuProcessStop(virQEMUDriverPtr driver,
|
||||||
|
|
||||||
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
||||||
cfg->libDir, vm->def->name));
|
cfg->libDir, vm->def->name));
|
||||||
if (tmppath)
|
|
||||||
virFileDeleteTree(tmppath);
|
virFileDeleteTree(tmppath);
|
||||||
VIR_FREE(tmppath);
|
VIR_FREE(tmppath);
|
||||||
|
|
||||||
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
|
||||||
cfg->channelTargetDir, vm->def->name));
|
cfg->channelTargetDir, vm->def->name));
|
||||||
if (tmppath)
|
|
||||||
virFileDeleteTree(tmppath);
|
virFileDeleteTree(tmppath);
|
||||||
VIR_FREE(tmppath);
|
VIR_FREE(tmppath);
|
||||||
|
|
||||||
|
|
|
@ -934,13 +934,17 @@ int virFileNBDDeviceAssociate(const char *file,
|
||||||
*/
|
*/
|
||||||
int virFileDeleteTree(const char *dir)
|
int virFileDeleteTree(const char *dir)
|
||||||
{
|
{
|
||||||
DIR *dh = opendir(dir);
|
DIR *dh;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
char *filepath = NULL;
|
char *filepath = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int direrr;
|
int direrr;
|
||||||
|
|
||||||
if (!dh) {
|
/* Silently return 0 if passed NULL or directory doesn't exist */
|
||||||
|
if (!dir || !virFileExists(dir))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!(dh = opendir(dir))) {
|
||||||
virReportSystemError(errno, _("Cannot open dir '%s'"),
|
virReportSystemError(errno, _("Cannot open dir '%s'"),
|
||||||
dir);
|
dir);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -65,7 +65,7 @@ myCleanup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mgr) {
|
if (mgr) {
|
||||||
if (mgr->stateDir && !getenv("LIBVIRT_SKIP_CLEANUP"))
|
if (!getenv("LIBVIRT_SKIP_CLEANUP"))
|
||||||
virFileDeleteTree(mgr->stateDir);
|
virFileDeleteTree(mgr->stateDir);
|
||||||
|
|
||||||
virObjectUnref(mgr->activePCIHostdevs);
|
virObjectUnref(mgr->activePCIHostdevs);
|
||||||
|
|
|
@ -241,7 +241,7 @@ mymain(void)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (tmpdir && getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
||||||
virFileDeleteTree(tmpdir);
|
virFileDeleteTree(tmpdir);
|
||||||
VIR_FREE(virscsi_prefix);
|
VIR_FREE(virscsi_prefix);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue