mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
Replace virFileAbsPath() with g_canonicalize_filename()
Signed-off-by: Luke Yue <lukedyue@gmail.com>
This commit is contained in:
parent
8d1559fbc3
commit
d2b6bab11c
@ -827,7 +827,7 @@ virDomainSave(virDomainPtr domain, const char *to)
|
||||
char *absolute_to;
|
||||
|
||||
/* We must absolutize the file path as the save is done out of process */
|
||||
if (virFileAbsPath(to, &absolute_to) < 0) {
|
||||
if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute output file path"));
|
||||
goto error;
|
||||
@ -915,7 +915,7 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,
|
||||
char *absolute_to;
|
||||
|
||||
/* We must absolutize the file path as the save is done out of process */
|
||||
if (virFileAbsPath(to, &absolute_to) < 0) {
|
||||
if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute output file path"));
|
||||
goto error;
|
||||
@ -965,7 +965,7 @@ virDomainRestore(virConnectPtr conn, const char *from)
|
||||
char *absolute_from;
|
||||
|
||||
/* We must absolutize the file path as the restore is done out of process */
|
||||
if (virFileAbsPath(from, &absolute_from) < 0) {
|
||||
if (!(absolute_from = g_canonicalize_filename(from, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute input file path"));
|
||||
goto error;
|
||||
@ -1039,7 +1039,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char *from, const char *dxml,
|
||||
char *absolute_from;
|
||||
|
||||
/* We must absolutize the file path as the restore is done out of process */
|
||||
if (virFileAbsPath(from, &absolute_from) < 0) {
|
||||
if (!(absolute_from = g_canonicalize_filename(from, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute input file path"));
|
||||
goto error;
|
||||
@ -1097,7 +1097,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file,
|
||||
char *absolute_file;
|
||||
|
||||
/* We must absolutize the file path as the read is done out of process */
|
||||
if (virFileAbsPath(file, &absolute_file) < 0) {
|
||||
if (!(absolute_file = g_canonicalize_filename(file, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute input file path"));
|
||||
goto error;
|
||||
@ -1170,7 +1170,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const char *file,
|
||||
char *absolute_file;
|
||||
|
||||
/* We must absolutize the file path as the read is done out of process */
|
||||
if (virFileAbsPath(file, &absolute_file) < 0) {
|
||||
if (!(absolute_file = g_canonicalize_filename(file, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute input file path"));
|
||||
goto error;
|
||||
@ -1245,7 +1245,7 @@ virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int flags)
|
||||
char *absolute_to;
|
||||
|
||||
/* We must absolutize the file path as the save is done out of process */
|
||||
if (virFileAbsPath(to, &absolute_to) < 0) {
|
||||
if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute core file path"));
|
||||
goto error;
|
||||
@ -1329,7 +1329,7 @@ virDomainCoreDumpWithFormat(virDomainPtr domain, const char *to,
|
||||
char *absolute_to;
|
||||
|
||||
/* We must absolutize the file path as the save is done out of process */
|
||||
if (virFileAbsPath(to, &absolute_to) < 0) {
|
||||
if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("could not build absolute core file path"));
|
||||
goto error;
|
||||
|
@ -2178,7 +2178,6 @@ virDirOpen;
|
||||
virDirOpenIfExists;
|
||||
virDirOpenQuiet;
|
||||
virDirRead;
|
||||
virFileAbsPath;
|
||||
virFileAccessibleAs;
|
||||
virFileActivateDirOverrideForLib;
|
||||
virFileActivateDirOverrideForProg;
|
||||
|
@ -1688,8 +1688,7 @@ virFindFileInPath(const char *file)
|
||||
if (!virFileIsExecutable(file))
|
||||
return NULL;
|
||||
|
||||
ignore_value(virFileAbsPath(file, &abspath));
|
||||
return abspath;
|
||||
return g_canonicalize_filename(file, NULL);
|
||||
}
|
||||
|
||||
/* copy PATH env so we can tweak it */
|
||||
@ -3146,27 +3145,6 @@ virFileOpenTty(int *ttyprimary G_GNUC_UNUSED,
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* Creates an absolute path for a potentially relative path.
|
||||
* Return 0 if the path was not relative, or on success.
|
||||
* Return -1 on error.
|
||||
*
|
||||
* You must free the result.
|
||||
*/
|
||||
int
|
||||
virFileAbsPath(const char *path, char **abspath)
|
||||
{
|
||||
if (g_path_is_absolute(path)) {
|
||||
*abspath = g_strdup(path);
|
||||
} else {
|
||||
g_autofree char *buf = g_get_current_dir();
|
||||
|
||||
*abspath = g_build_filename(buf, path, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove spurious / characters from a path. The result must be freed */
|
||||
char *
|
||||
virFileSanitizePath(const char *path)
|
||||
|
@ -283,9 +283,6 @@ char *virFileBuildPath(const char *dir,
|
||||
const char *name,
|
||||
const char *ext) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
int virFileAbsPath(const char *path,
|
||||
char **abspath) G_GNUC_WARN_UNUSED_RESULT;
|
||||
void virFileRemoveLastComponent(char *path);
|
||||
|
||||
int virFileOpenTty(int *ttymaster,
|
||||
|
@ -1512,7 +1512,7 @@ virLogParseOutput(const char *src)
|
||||
#endif
|
||||
break;
|
||||
case VIR_LOG_TO_FILE:
|
||||
if (virFileAbsPath(tokens[2], &abspath) < 0)
|
||||
if (!(abspath = g_canonicalize_filename(tokens[2], NULL)))
|
||||
return NULL;
|
||||
ret = virLogNewOutputToFile(prio, abspath);
|
||||
VIR_FREE(abspath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user