mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 03:21:19 +00:00
util: Implement and use virFileIsRegular() rather than d_type
The dirent's d_type field is not portable to all platforms. So we have to use stat() to determine the type of file for the functions that need to be cross-platform. Fix virFileChownFiles() by calling the new virFileIsRegular() function. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
ed29219f21
commit
6d21d9bccb
@ -1796,6 +1796,7 @@ virFileIsDir;
|
|||||||
virFileIsExecutable;
|
virFileIsExecutable;
|
||||||
virFileIsLink;
|
virFileIsLink;
|
||||||
virFileIsMountPoint;
|
virFileIsMountPoint;
|
||||||
|
virFileIsRegular;
|
||||||
virFileIsSharedFS;
|
virFileIsSharedFS;
|
||||||
virFileIsSharedFSType;
|
virFileIsSharedFSType;
|
||||||
virFileLength;
|
virFileLength;
|
||||||
|
@ -1851,6 +1851,15 @@ virFileIsDir(const char *path)
|
|||||||
return (stat(path, &s) == 0) && S_ISDIR(s.st_mode);
|
return (stat(path, &s) == 0) && S_ISDIR(s.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virFileIsRegular(const char *path)
|
||||||
|
{
|
||||||
|
struct stat s;
|
||||||
|
return (stat(path, &s) == 0) && S_ISREG(s.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virFileExists: Check for presence of file
|
* virFileExists: Check for presence of file
|
||||||
* @path: Path of file to check
|
* @path: Path of file to check
|
||||||
@ -3005,12 +3014,13 @@ int virFileChownFiles(const char *name,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while ((direrr = virDirRead(dir, &ent, name)) > 0) {
|
while ((direrr = virDirRead(dir, &ent, name)) > 0) {
|
||||||
if (ent->d_type != DT_REG)
|
VIR_FREE(path);
|
||||||
continue;
|
|
||||||
|
|
||||||
if (virAsprintf(&path, "%s/%s", name, ent->d_name) < 0)
|
if (virAsprintf(&path, "%s/%s", name, ent->d_name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!virFileIsRegular(path))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (chown(path, uid, gid) < 0) {
|
if (chown(path, uid, gid) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot chown '%s' to (%u, %u)"),
|
_("cannot chown '%s' to (%u, %u)"),
|
||||||
@ -3018,7 +3028,6 @@ int virFileChownFiles(const char *name,
|
|||||||
(unsigned int) gid);
|
(unsigned int) gid);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
VIR_FREE(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direrr < 0)
|
if (direrr < 0)
|
||||||
|
@ -194,6 +194,7 @@ off_t virFileLength(const char *path, int fd) ATTRIBUTE_NONNULL(1);
|
|||||||
bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1);
|
bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1);
|
||||||
bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NOINLINE;
|
bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NOINLINE;
|
||||||
bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1);
|
bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1);
|
||||||
|
bool virFileIsRegular(const char *file) ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
VIR_FILE_SHFS_NFS = (1 << 0),
|
VIR_FILE_SHFS_NFS = (1 << 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user