aboutsummaryrefslogtreecommitdiff
path: root/src/win/fs.c
diff options
context:
space:
mode:
authorSk Sajidul Kadir <sheikh.sajid522@gmail.com>2020-02-29 23:29:15 +1100
committerBen Noordhuis <info@bnoordhuis.nl>2020-04-14 10:06:33 +0200
commitbd4292385f5b0a1be85d6c7dd7b51d4b22a4289c (patch)
tree6be0fc63b5956f1a08d630cd836eafba2ac9226c /src/win/fs.c
parentdc7c874660526e4ed70c7c7579b974283c9ad6e0 (diff)
downloadlibuv-bd4292385f5b0a1be85d6c7dd7b51d4b22a4289c.tar.gz
libuv-bd4292385f5b0a1be85d6c7dd7b51d4b22a4289c.zip
fs: add uv_fs_lutime()
PR-URL: https://github.com/libuv/libuv/pull/2723 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/win/fs.c')
-rw-r--r--src/win/fs.c76
1 files changed, 65 insertions, 11 deletions
diff --git a/src/win/fs.c b/src/win/fs.c
index 8502b072..209f3d57 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -2225,34 +2225,68 @@ INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) {
return 0;
}
-
-static void fs__utime(uv_fs_t* req) {
+INLINE static DWORD fs__utime_impl_from_path(WCHAR* path,
+ double atime,
+ double mtime,
+ int do_lutime) {
HANDLE handle;
+ DWORD flags;
+ DWORD ret;
- handle = CreateFileW(req->file.pathw,
+ flags = FILE_FLAG_BACKUP_SEMANTICS;
+ if (do_lutime) {
+ flags |= FILE_FLAG_OPEN_REPARSE_POINT;
+ }
+
+ handle = CreateFileW(path,
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS,
+ flags,
NULL);
if (handle == INVALID_HANDLE_VALUE) {
- SET_REQ_WIN32_ERROR(req, GetLastError());
- return;
+ ret = GetLastError();
+ } else if (fs__utime_handle(handle, atime, mtime) != 0) {
+ ret = GetLastError();
+ } else {
+ ret = 0;
}
- if (fs__utime_handle(handle, req->fs.time.atime, req->fs.time.mtime) != 0) {
- SET_REQ_WIN32_ERROR(req, GetLastError());
- CloseHandle(handle);
+ CloseHandle(handle);
+ return ret;
+}
+
+INLINE static void fs__utime_impl(uv_fs_t* req, int do_lutime) {
+ DWORD error;
+
+ error = fs__utime_impl_from_path(req->file.pathw,
+ req->fs.time.atime,
+ req->fs.time.mtime,
+ do_lutime);
+
+ if (error != 0) {
+ if (do_lutime &&
+ (error == ERROR_SYMLINK_NOT_SUPPORTED ||
+ error == ERROR_NOT_A_REPARSE_POINT)) {
+ /* Opened file is a reparse point but not a symlink. Try again. */
+ fs__utime_impl(req, 0);
+ } else {
+ /* utime failed. */
+ SET_REQ_WIN32_ERROR(req, error);
+ }
+
return;
}
- CloseHandle(handle);
-
req->result = 0;
}
+static void fs__utime(uv_fs_t* req) {
+ fs__utime_impl(req, /* do_lutime */ 0);
+}
+
static void fs__futime(uv_fs_t* req) {
int fd = req->file.fd;
@@ -2274,6 +2308,10 @@ static void fs__futime(uv_fs_t* req) {
req->result = 0;
}
+static void fs__lutime(uv_fs_t* req) {
+ fs__utime_impl(req, /* do_lutime */ 1);
+}
+
static void fs__link(uv_fs_t* req) {
DWORD r = CreateHardLinkW(req->fs.info.new_pathw, req->file.pathw, NULL);
@@ -2670,6 +2708,7 @@ static void uv__fs_work(struct uv__work* w) {
XX(FTRUNCATE, ftruncate)
XX(UTIME, utime)
XX(FUTIME, futime)
+ XX(LUTIME, lutime)
XX(ACCESS, access)
XX(CHMOD, chmod)
XX(FCHMOD, fchmod)
@@ -3222,6 +3261,21 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime,
POST;
}
+int uv_fs_lutime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
+ double mtime, uv_fs_cb cb) {
+ int err;
+
+ INIT(UV_FS_LUTIME);
+ err = fs__capture_path(req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
+
+ req->fs.time.atime = atime;
+ req->fs.time.mtime = mtime;
+ POST;
+}
+
int uv_fs_statfs(uv_loop_t* loop,
uv_fs_t* req,