On 01/11/2012 09:33 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Add a virFileTouch API which ensures that a file will always
exist, even if zero length
* src/lxc/lxc_container.c, src/util/virfile.h: virFileTouch
This line is not quite accurate,
---
src/util/virfile.c | 21 +++++++++++++++++++++
src/util/virfile.h | 2 ++
2 files changed, 23 insertions(+), 0 deletions(-)
to this diffstat (drop lxc_container). Otherwise, looks like a useful API.
diff --git a/src/util/virfile.c b/src/util/virfile.c
index cbc3fcc..e6b469c 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -390,3 +390,24 @@ cleanup:
}
return ret;
}
+
+
+int virFileTouch(const char *path, mode_t mode)
+{
+ int fd = -1;
+
+ if ((fd = open(path, O_WRONLY | O_CREAT, mode)) < 0) {
+ virReportSystemError(errno, _("cannot create file '%s'"),
+ path);
+ return -1;
Should we be using virFileOpenAs() for the sake of touching a file with
different permissions on a root-squash NFS server?
In particular, I wonder if any of qemu_driver.c could reuse this
function, if it were to use virFileOpenAs() - for example, creating a
qemu snapshot requires that a file already exist and be empty before
making the monitor call.
ACK - any change to use virFileOpenAs can come as a later patch.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org