You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/10/24 22:46:36 UTC
[2/3] git commit: Added os::utime() to update access/modification
times.
Added os::utime() to update access/modification times.
Review: https://reviews.apache.org/r/14662/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b41dbe41
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b41dbe41
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b41dbe41
Branch: refs/heads/master
Commit: b41dbe41795a36df5202dc7264d8de6045fccaa5
Parents: 8cbeefa
Author: Vinod Kone <vi...@twitter.com>
Authored: Thu Oct 17 10:45:48 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Thu Oct 24 13:36:07 2013 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/os.hpp | 30 ++++++++++++++------
1 file changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b41dbe41/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 728122e..18d8b7f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <utime.h>
#include <glog/logging.h>
@@ -221,19 +222,32 @@ inline Try<bool> isNonblock(int fd)
}
+// Sets the access and modification times of 'path' to the current time.
+inline Try<Nothing> utime(const std::string& path)
+{
+ if (::utime(path.c_str(), NULL) == -1) {
+ return ErrnoError();
+ }
+
+ return Nothing();
+}
+
+
inline Try<Nothing> touch(const std::string& path)
{
- Try<int> fd =
- open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
+ if (!exists(path)) {
+ Try<int> fd =
+ open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
- if (fd.isError()) {
- return Error("Failed to open file '" + path + "'");
+ if (fd.isError()) {
+ return Error("Failed to open file: " + fd.error());
+ }
+
+ return close(fd.get());
}
- // TODO(benh): Is opening/closing sufficient to have the same
- // semantics as the touch utility (i.e., doesn't the utility change
- // the modified date)?
- return close(fd.get());
+ // Update the access and modification times.
+ return utime(path);
}