visaljs 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/cli.js +155 -27
- package/node/include/js_node.h +2 -0
- package/node/prelude/async_hooks.js +0 -0
- package/node/prelude/buffer.js +0 -0
- package/node/prelude/events.js +0 -0
- package/node/prelude/fs.js +0 -0
- package/node/prelude/http2.js +0 -0
- package/node/prelude/internal/crypto/asym.js +0 -0
- package/node/prelude/internal/crypto/cipher.js +0 -0
- package/node/prelude/internal/crypto/kdf.js +0 -0
- package/node/prelude/internal/crypto/keys.js +0 -0
- package/node/prelude/internal/crypto/random.js +0 -0
- package/node/prelude/internal/crypto/util.js +0 -0
- package/node/prelude/internal/errors.js +0 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/tls/wrap.js +5 -2
- package/node/prelude/module.js +0 -0
- package/node/prelude/net.js +1 -2
- package/node/prelude/os.js +2 -2
- package/node/prelude/path.js +0 -0
- package/node/prelude/process.js +0 -0
- package/node/prelude/querystring.js +0 -0
- package/node/prelude/stream.js +0 -0
- package/node/prelude/stream_promises.js +0 -0
- package/node/prelude/stream_web.js +0 -0
- package/node/prelude/string_decoder.js +0 -0
- package/node/prelude/tty.js +0 -0
- package/node/prelude/url.js +0 -0
- package/node/prelude/util.js +0 -0
- package/node/prelude/zlib.js +0 -0
- package/node/src/host_fs.c +10 -2
- package/node/src/host_os.c +0 -0
- package/node/src/host_sys.c +44 -32
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/libuv/src/win/async.c +98 -0
- package/node/third_party/libuv/src/win/atomicops-inl.h +61 -0
- package/node/third_party/libuv/src/win/core.c +683 -0
- package/node/third_party/libuv/src/win/detect-wakeup.c +56 -0
- package/node/third_party/libuv/src/win/dl.c +135 -0
- package/node/third_party/libuv/src/win/error.c +183 -0
- package/node/third_party/libuv/src/win/fs-event.c +620 -0
- package/node/third_party/libuv/src/win/fs-fd-hash-inl.h +200 -0
- package/node/third_party/libuv/src/win/fs.c +3774 -0
- package/node/third_party/libuv/src/win/getaddrinfo.c +388 -0
- package/node/third_party/libuv/src/win/getnameinfo.c +146 -0
- package/node/third_party/libuv/src/win/handle-inl.h +180 -0
- package/node/third_party/libuv/src/win/handle.c +162 -0
- package/node/third_party/libuv/src/win/internal.h +335 -0
- package/node/third_party/libuv/src/win/loop-watcher.c +122 -0
- package/node/third_party/libuv/src/win/pipe.c +2725 -0
- package/node/third_party/libuv/src/win/poll.c +586 -0
- package/node/third_party/libuv/src/win/process-stdio.c +419 -0
- package/node/third_party/libuv/src/win/process.c +1407 -0
- package/node/third_party/libuv/src/win/req-inl.h +214 -0
- package/node/third_party/libuv/src/win/signal.c +282 -0
- package/node/third_party/libuv/src/win/snprintf.c +42 -0
- package/node/third_party/libuv/src/win/stream-inl.h +54 -0
- package/node/third_party/libuv/src/win/stream.c +252 -0
- package/node/third_party/libuv/src/win/tcp.c +1674 -0
- package/node/third_party/libuv/src/win/thread.c +568 -0
- package/node/third_party/libuv/src/win/tty.c +2460 -0
- package/node/third_party/libuv/src/win/udp.c +1162 -0
- package/node/third_party/libuv/src/win/util.c +1750 -0
- package/node/third_party/libuv/src/win/winapi.c +144 -0
- package/node/third_party/libuv/src/win/winapi.h +4831 -0
- package/node/third_party/libuv/src/win/winsock.c +575 -0
- package/node/third_party/libuv/src/win/winsock.h +160 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/package.json +3 -2
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +0 -0
- package/runtime/include/js_bigint.h +0 -0
- package/runtime/include/js_buffer.h +0 -0
- package/runtime/include/js_builtins.h +0 -0
- package/runtime/include/js_console.h +0 -0
- package/runtime/include/js_convert.h +0 -0
- package/runtime/include/js_core.def +0 -0
- package/runtime/include/js_error.h +0 -0
- package/runtime/include/js_exception.h +0 -0
- package/runtime/include/js_function.h +0 -0
- package/runtime/include/js_gc.h +0 -0
- package/runtime/include/js_generator.h +0 -0
- package/runtime/include/js_host.h +0 -0
- package/runtime/include/js_jobs.h +0 -0
- package/runtime/include/js_module.h +0 -0
- package/runtime/include/js_object.h +0 -0
- package/runtime/include/js_ops.h +0 -0
- package/runtime/include/js_promise.h +0 -0
- package/runtime/include/js_regexp.h +0 -0
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +0 -0
- package/runtime/include/js_web.h +0 -0
- package/runtime/include/jscell.h +0 -0
- package/runtime/include/jscontext.h +0 -0
- package/runtime/include/jsnum.h +0 -0
- package/runtime/include/jsstring.h +0 -0
- package/runtime/include/jsvalue.h +0 -0
- package/runtime/src/arguments.c +0 -0
- package/runtime/src/array.c +0 -0
- package/runtime/src/arraybuffer.c +0 -0
- package/runtime/src/async_iter.c +0 -0
- package/runtime/src/atoms.c +0 -0
- package/runtime/src/base64.c +0 -0
- package/runtime/src/bigint.c +0 -0
- package/runtime/src/blob.c +0 -0
- package/runtime/src/boringssl_support.cc +4 -1
- package/runtime/src/buffer.c +0 -0
- package/runtime/src/builtin_table.c +0 -0
- package/runtime/src/builtins.c +0 -0
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +0 -0
- package/runtime/src/components.c +0 -0
- package/runtime/src/console.c +0 -0
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +0 -0
- package/runtime/src/crypto.c +0 -0
- package/runtime/src/crypto_host.c +0 -0
- package/runtime/src/crypto_kdf.c +0 -0
- package/runtime/src/crypto_key.c +0 -0
- package/runtime/src/date.c +0 -0
- package/runtime/src/domexception.c +0 -0
- package/runtime/src/elements.c +0 -0
- package/runtime/src/elements.h +0 -0
- package/runtime/src/encoding.c +0 -0
- package/runtime/src/error.c +0 -0
- package/runtime/src/events.c +0 -0
- package/runtime/src/exception.c +0 -0
- package/runtime/src/fetch.c +0 -0
- package/runtime/src/function.c +0 -0
- package/runtime/src/gc.c +0 -0
- package/runtime/src/generator.c +0 -0
- package/runtime/src/global.c +0 -0
- package/runtime/src/headers.c +0 -0
- package/runtime/src/inspect.c +0 -0
- package/runtime/src/internal.h +0 -0
- package/runtime/src/iterate.c +0 -0
- package/runtime/src/iterator.c +0 -0
- package/runtime/src/jobs.c +0 -0
- package/runtime/src/jsnum.c +0 -0
- package/runtime/src/json.c +0 -0
- package/runtime/src/math.c +0 -0
- package/runtime/src/module.c +0 -0
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +0 -0
- package/runtime/src/ops.c +0 -0
- package/runtime/src/os.c +0 -0
- package/runtime/src/os.h +0 -0
- package/runtime/src/process.c +7 -0
- package/runtime/src/promise.c +0 -0
- package/runtime/src/proxy.c +0 -0
- package/runtime/src/reflect.c +0 -0
- package/runtime/src/regexp.c +0 -0
- package/runtime/src/regexp_anchor.h +0 -0
- package/runtime/src/regexp_message.h +0 -0
- package/runtime/src/shape.c +0 -0
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +0 -0
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +0 -0
- package/runtime/src/string_builtins.c +0 -0
- package/runtime/src/symbol.c +0 -0
- package/runtime/src/test_host.c +0 -0
- package/runtime/src/typedarray.c +0 -0
- package/runtime/src/tznames.gen.h +0 -0
- package/runtime/src/uri.c +0 -0
- package/runtime/src/url.c +0 -0
- package/runtime/src/weak.c +0 -0
- package/runtime/src/web.c +0 -0
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +0 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +0 -0
- package/runtime/third_party/ada-idna/convert.mjs +0 -0
- package/runtime/third_party/ada-idna/idna.c +0 -0
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +0 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/README.md +0 -0
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +0 -0
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
* furnished to do so, subject to the following conditions:
|
|
9
|
+
*
|
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
|
11
|
+
* all copies or substantial portions of the Software.
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19
|
+
* IN THE SOFTWARE.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
#include <errno.h>
|
|
24
|
+
#include <stdio.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
|
|
27
|
+
#include "uv.h"
|
|
28
|
+
#include "internal.h"
|
|
29
|
+
#include "handle-inl.h"
|
|
30
|
+
#include "req-inl.h"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const unsigned int uv_directory_watcher_buffer_size = 4096;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
static void uv__fs_event_queue_readdirchanges(uv_loop_t* loop,
|
|
37
|
+
uv_fs_event_t* handle) {
|
|
38
|
+
assert(handle->dir_handle != INVALID_HANDLE_VALUE);
|
|
39
|
+
assert(!handle->req_pending);
|
|
40
|
+
|
|
41
|
+
memset(&(handle->req.u.io.overlapped), 0,
|
|
42
|
+
sizeof(handle->req.u.io.overlapped));
|
|
43
|
+
if (!ReadDirectoryChangesW(handle->dir_handle,
|
|
44
|
+
handle->buffer,
|
|
45
|
+
uv_directory_watcher_buffer_size,
|
|
46
|
+
(handle->flags & UV_FS_EVENT_RECURSIVE) ? TRUE : FALSE,
|
|
47
|
+
FILE_NOTIFY_CHANGE_FILE_NAME |
|
|
48
|
+
FILE_NOTIFY_CHANGE_DIR_NAME |
|
|
49
|
+
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
|
50
|
+
FILE_NOTIFY_CHANGE_SIZE |
|
|
51
|
+
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
|
52
|
+
FILE_NOTIFY_CHANGE_LAST_ACCESS |
|
|
53
|
+
FILE_NOTIFY_CHANGE_CREATION |
|
|
54
|
+
FILE_NOTIFY_CHANGE_SECURITY,
|
|
55
|
+
NULL,
|
|
56
|
+
&handle->req.u.io.overlapped,
|
|
57
|
+
NULL)) {
|
|
58
|
+
/* Make this req pending reporting an error. */
|
|
59
|
+
SET_REQ_ERROR(&handle->req, GetLastError());
|
|
60
|
+
uv__insert_pending_req(loop, (uv_req_t*)&handle->req);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
handle->req_pending = 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void uv__relative_path(const WCHAR* filename,
|
|
67
|
+
const WCHAR* dir,
|
|
68
|
+
WCHAR** relpath) {
|
|
69
|
+
size_t relpathlen;
|
|
70
|
+
size_t filenamelen = wcslen(filename);
|
|
71
|
+
size_t dirlen = wcslen(dir);
|
|
72
|
+
assert(!_wcsnicmp(filename, dir, dirlen));
|
|
73
|
+
if (dirlen > 0 && dir[dirlen - 1] == '\\')
|
|
74
|
+
dirlen--;
|
|
75
|
+
relpathlen = filenamelen - dirlen - 1;
|
|
76
|
+
*relpath = uv__malloc((relpathlen + 1) * sizeof(WCHAR));
|
|
77
|
+
if (!*relpath)
|
|
78
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
79
|
+
wcsncpy(*relpath, filename + dirlen + 1, relpathlen);
|
|
80
|
+
(*relpath)[relpathlen] = L'\0';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static int uv__split_path(const WCHAR* filename, WCHAR** dir,
|
|
84
|
+
WCHAR** file) {
|
|
85
|
+
size_t len, i;
|
|
86
|
+
DWORD dir_len;
|
|
87
|
+
|
|
88
|
+
if (filename == NULL) {
|
|
89
|
+
if (dir != NULL)
|
|
90
|
+
*dir = NULL;
|
|
91
|
+
*file = NULL;
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
len = wcslen(filename);
|
|
96
|
+
i = len;
|
|
97
|
+
while (i > 0 && filename[--i] != '\\' && filename[i] != '/');
|
|
98
|
+
|
|
99
|
+
if (i == 0) {
|
|
100
|
+
if (dir) {
|
|
101
|
+
dir_len = GetCurrentDirectoryW(0, NULL);
|
|
102
|
+
if (dir_len == 0) {
|
|
103
|
+
return -1;
|
|
104
|
+
}
|
|
105
|
+
*dir = (WCHAR*)uv__malloc(dir_len * sizeof(WCHAR));
|
|
106
|
+
if (!*dir) {
|
|
107
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!GetCurrentDirectoryW(dir_len, *dir)) {
|
|
111
|
+
uv__free(*dir);
|
|
112
|
+
*dir = NULL;
|
|
113
|
+
return -1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
*file = _wcsdup(filename);
|
|
118
|
+
} else {
|
|
119
|
+
if (dir) {
|
|
120
|
+
*dir = (WCHAR*)uv__malloc((i + 2) * sizeof(WCHAR));
|
|
121
|
+
if (!*dir) {
|
|
122
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
123
|
+
}
|
|
124
|
+
wcsncpy(*dir, filename, i + 1);
|
|
125
|
+
(*dir)[i + 1] = L'\0';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
*file = (WCHAR*)uv__malloc((len - i) * sizeof(WCHAR));
|
|
129
|
+
if (!*file) {
|
|
130
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
131
|
+
}
|
|
132
|
+
wcsncpy(*file, filename + i + 1, len - i - 1);
|
|
133
|
+
(*file)[len - i - 1] = L'\0';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
|
|
141
|
+
uv__handle_init(loop, (uv_handle_t*) handle, UV_FS_EVENT);
|
|
142
|
+
handle->dir_handle = INVALID_HANDLE_VALUE;
|
|
143
|
+
handle->buffer = NULL;
|
|
144
|
+
handle->req_pending = 0;
|
|
145
|
+
handle->filew = NULL;
|
|
146
|
+
handle->short_filew = NULL;
|
|
147
|
+
handle->dirw = NULL;
|
|
148
|
+
|
|
149
|
+
UV_REQ_INIT(&handle->req, UV_FS_EVENT_REQ);
|
|
150
|
+
handle->req.data = handle;
|
|
151
|
+
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
int uv_fs_event_start(uv_fs_event_t* handle,
|
|
157
|
+
uv_fs_event_cb cb,
|
|
158
|
+
const char* path,
|
|
159
|
+
unsigned int flags) {
|
|
160
|
+
int is_path_dir;
|
|
161
|
+
size_t size;
|
|
162
|
+
DWORD attr, last_error;
|
|
163
|
+
WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL;
|
|
164
|
+
DWORD short_path_buffer_len;
|
|
165
|
+
WCHAR *short_path_buffer;
|
|
166
|
+
WCHAR* short_path, *long_path;
|
|
167
|
+
|
|
168
|
+
short_path = NULL;
|
|
169
|
+
if (uv__is_active(handle))
|
|
170
|
+
return UV_EINVAL;
|
|
171
|
+
|
|
172
|
+
handle->cb = cb;
|
|
173
|
+
handle->path = uv__strdup(path);
|
|
174
|
+
if (!handle->path) {
|
|
175
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
uv__handle_start(handle);
|
|
179
|
+
|
|
180
|
+
last_error = uv__convert_utf8_to_utf16(path, &pathw);
|
|
181
|
+
if (last_error)
|
|
182
|
+
goto error_uv;
|
|
183
|
+
|
|
184
|
+
/* Determine whether path is a file or a directory. */
|
|
185
|
+
attr = GetFileAttributesW(pathw);
|
|
186
|
+
if (attr == INVALID_FILE_ATTRIBUTES) {
|
|
187
|
+
last_error = GetLastError();
|
|
188
|
+
goto error;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
is_path_dir = (attr & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
|
|
192
|
+
|
|
193
|
+
if (is_path_dir) {
|
|
194
|
+
/* path is a directory, so that's the directory that we will watch. */
|
|
195
|
+
|
|
196
|
+
/* Convert to long path. */
|
|
197
|
+
size = GetLongPathNameW(pathw, NULL, 0);
|
|
198
|
+
|
|
199
|
+
if (size) {
|
|
200
|
+
long_path = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
|
|
201
|
+
if (!long_path) {
|
|
202
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
size = GetLongPathNameW(pathw, long_path, size);
|
|
206
|
+
if (size) {
|
|
207
|
+
long_path[size] = '\0';
|
|
208
|
+
} else {
|
|
209
|
+
uv__free(long_path);
|
|
210
|
+
long_path = NULL;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (long_path) {
|
|
214
|
+
uv__free(pathw);
|
|
215
|
+
pathw = long_path;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
dir_to_watch = pathw;
|
|
220
|
+
} else {
|
|
221
|
+
/*
|
|
222
|
+
* path is a file. So we split path into dir & file parts, and
|
|
223
|
+
* watch the dir directory.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
/* Convert to short path. */
|
|
227
|
+
short_path_buffer = NULL;
|
|
228
|
+
short_path_buffer_len = GetShortPathNameW(pathw, NULL, 0);
|
|
229
|
+
if (short_path_buffer_len == 0) {
|
|
230
|
+
goto short_path_done;
|
|
231
|
+
}
|
|
232
|
+
short_path_buffer = uv__malloc(short_path_buffer_len * sizeof(WCHAR));
|
|
233
|
+
if (short_path_buffer == NULL) {
|
|
234
|
+
goto short_path_done;
|
|
235
|
+
}
|
|
236
|
+
if (GetShortPathNameW(pathw,
|
|
237
|
+
short_path_buffer,
|
|
238
|
+
short_path_buffer_len) == 0) {
|
|
239
|
+
uv__free(short_path_buffer);
|
|
240
|
+
short_path_buffer = NULL;
|
|
241
|
+
}
|
|
242
|
+
short_path_done:
|
|
243
|
+
short_path = short_path_buffer;
|
|
244
|
+
|
|
245
|
+
if (uv__split_path(pathw, &dir, &handle->filew) != 0) {
|
|
246
|
+
last_error = GetLastError();
|
|
247
|
+
goto error;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (uv__split_path(short_path, NULL, &handle->short_filew) != 0) {
|
|
251
|
+
last_error = GetLastError();
|
|
252
|
+
goto error;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
dir_to_watch = dir;
|
|
256
|
+
uv__free(short_path);
|
|
257
|
+
short_path = NULL;
|
|
258
|
+
uv__free(pathw);
|
|
259
|
+
pathw = NULL;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
handle->dir_handle = CreateFileW(dir_to_watch,
|
|
263
|
+
FILE_LIST_DIRECTORY,
|
|
264
|
+
FILE_SHARE_READ | FILE_SHARE_DELETE |
|
|
265
|
+
FILE_SHARE_WRITE,
|
|
266
|
+
NULL,
|
|
267
|
+
OPEN_EXISTING,
|
|
268
|
+
FILE_FLAG_BACKUP_SEMANTICS |
|
|
269
|
+
FILE_FLAG_OVERLAPPED,
|
|
270
|
+
NULL);
|
|
271
|
+
|
|
272
|
+
if (dir) {
|
|
273
|
+
uv__free(dir);
|
|
274
|
+
dir = NULL;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (handle->dir_handle == INVALID_HANDLE_VALUE) {
|
|
278
|
+
last_error = GetLastError();
|
|
279
|
+
goto error;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (CreateIoCompletionPort(handle->dir_handle,
|
|
283
|
+
handle->loop->iocp,
|
|
284
|
+
(ULONG_PTR)handle,
|
|
285
|
+
0) == NULL) {
|
|
286
|
+
last_error = GetLastError();
|
|
287
|
+
goto error;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!handle->buffer) {
|
|
291
|
+
handle->buffer = (char*)uv__malloc(uv_directory_watcher_buffer_size);
|
|
292
|
+
}
|
|
293
|
+
if (!handle->buffer) {
|
|
294
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
memset(&(handle->req.u.io.overlapped), 0,
|
|
298
|
+
sizeof(handle->req.u.io.overlapped));
|
|
299
|
+
|
|
300
|
+
if (!ReadDirectoryChangesW(handle->dir_handle,
|
|
301
|
+
handle->buffer,
|
|
302
|
+
uv_directory_watcher_buffer_size,
|
|
303
|
+
(flags & UV_FS_EVENT_RECURSIVE) ? TRUE : FALSE,
|
|
304
|
+
FILE_NOTIFY_CHANGE_FILE_NAME |
|
|
305
|
+
FILE_NOTIFY_CHANGE_DIR_NAME |
|
|
306
|
+
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
|
307
|
+
FILE_NOTIFY_CHANGE_SIZE |
|
|
308
|
+
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
|
309
|
+
FILE_NOTIFY_CHANGE_LAST_ACCESS |
|
|
310
|
+
FILE_NOTIFY_CHANGE_CREATION |
|
|
311
|
+
FILE_NOTIFY_CHANGE_SECURITY,
|
|
312
|
+
NULL,
|
|
313
|
+
&handle->req.u.io.overlapped,
|
|
314
|
+
NULL)) {
|
|
315
|
+
last_error = GetLastError();
|
|
316
|
+
goto error;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
assert(is_path_dir ? pathw != NULL : pathw == NULL);
|
|
320
|
+
handle->dirw = pathw;
|
|
321
|
+
handle->req_pending = 1;
|
|
322
|
+
return 0;
|
|
323
|
+
|
|
324
|
+
error:
|
|
325
|
+
last_error = uv_translate_sys_error(last_error);
|
|
326
|
+
|
|
327
|
+
error_uv:
|
|
328
|
+
if (handle->path) {
|
|
329
|
+
uv__free(handle->path);
|
|
330
|
+
handle->path = NULL;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (handle->filew) {
|
|
334
|
+
uv__free(handle->filew);
|
|
335
|
+
handle->filew = NULL;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (handle->short_filew) {
|
|
339
|
+
uv__free(handle->short_filew);
|
|
340
|
+
handle->short_filew = NULL;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
uv__free(pathw);
|
|
344
|
+
|
|
345
|
+
if (handle->dir_handle != INVALID_HANDLE_VALUE) {
|
|
346
|
+
CloseHandle(handle->dir_handle);
|
|
347
|
+
handle->dir_handle = INVALID_HANDLE_VALUE;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (handle->buffer) {
|
|
351
|
+
uv__free(handle->buffer);
|
|
352
|
+
handle->buffer = NULL;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (uv__is_active(handle))
|
|
356
|
+
uv__handle_stop(handle);
|
|
357
|
+
|
|
358
|
+
uv__free(short_path);
|
|
359
|
+
|
|
360
|
+
return last_error;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
int uv_fs_event_stop(uv_fs_event_t* handle) {
|
|
365
|
+
if (!uv__is_active(handle))
|
|
366
|
+
return 0;
|
|
367
|
+
|
|
368
|
+
if (handle->dir_handle != INVALID_HANDLE_VALUE) {
|
|
369
|
+
CloseHandle(handle->dir_handle);
|
|
370
|
+
handle->dir_handle = INVALID_HANDLE_VALUE;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
uv__handle_stop(handle);
|
|
374
|
+
|
|
375
|
+
if (handle->filew) {
|
|
376
|
+
uv__free(handle->filew);
|
|
377
|
+
handle->filew = NULL;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (handle->short_filew) {
|
|
381
|
+
uv__free(handle->short_filew);
|
|
382
|
+
handle->short_filew = NULL;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (handle->path) {
|
|
386
|
+
uv__free(handle->path);
|
|
387
|
+
handle->path = NULL;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (handle->dirw) {
|
|
391
|
+
uv__free(handle->dirw);
|
|
392
|
+
handle->dirw = NULL;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
static int file_info_cmp(WCHAR* str, WCHAR* file_name, size_t file_name_len) {
|
|
400
|
+
size_t str_len;
|
|
401
|
+
|
|
402
|
+
if (str == NULL)
|
|
403
|
+
return -1;
|
|
404
|
+
|
|
405
|
+
str_len = wcslen(str);
|
|
406
|
+
|
|
407
|
+
/*
|
|
408
|
+
Since we only care about equality, return early if the strings
|
|
409
|
+
aren't the same length
|
|
410
|
+
*/
|
|
411
|
+
if (str_len != (file_name_len / sizeof(WCHAR)))
|
|
412
|
+
return -1;
|
|
413
|
+
|
|
414
|
+
return _wcsnicmp(str, file_name, str_len);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
|
|
419
|
+
uv_fs_event_t* handle) {
|
|
420
|
+
FILE_NOTIFY_INFORMATION* file_info;
|
|
421
|
+
int err, sizew, size;
|
|
422
|
+
char* filename = NULL;
|
|
423
|
+
WCHAR* filenamew = NULL;
|
|
424
|
+
WCHAR* long_filenamew = NULL;
|
|
425
|
+
DWORD offset = 0;
|
|
426
|
+
|
|
427
|
+
assert(req->type == UV_FS_EVENT_REQ);
|
|
428
|
+
assert(handle->req_pending);
|
|
429
|
+
handle->req_pending = 0;
|
|
430
|
+
|
|
431
|
+
/* Don't report any callbacks if:
|
|
432
|
+
* - We're closing, just push the handle onto the endgame queue
|
|
433
|
+
* - We are not active, just ignore the callback
|
|
434
|
+
*/
|
|
435
|
+
if (!uv__is_active(handle)) {
|
|
436
|
+
if (handle->flags & UV_HANDLE_CLOSING) {
|
|
437
|
+
uv__want_endgame(loop, (uv_handle_t*) handle);
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
file_info = (FILE_NOTIFY_INFORMATION*)(handle->buffer + offset);
|
|
443
|
+
|
|
444
|
+
if (REQ_SUCCESS(req)) {
|
|
445
|
+
if (req->u.io.overlapped.InternalHigh > 0) {
|
|
446
|
+
do {
|
|
447
|
+
file_info = (FILE_NOTIFY_INFORMATION*)((char*)file_info + offset);
|
|
448
|
+
assert(!filename);
|
|
449
|
+
assert(!filenamew);
|
|
450
|
+
assert(!long_filenamew);
|
|
451
|
+
|
|
452
|
+
/*
|
|
453
|
+
* Fire the event only if we were asked to watch a directory,
|
|
454
|
+
* or if the filename filter matches.
|
|
455
|
+
*/
|
|
456
|
+
if (handle->dirw ||
|
|
457
|
+
file_info_cmp(handle->filew,
|
|
458
|
+
file_info->FileName,
|
|
459
|
+
file_info->FileNameLength) == 0 ||
|
|
460
|
+
file_info_cmp(handle->short_filew,
|
|
461
|
+
file_info->FileName,
|
|
462
|
+
file_info->FileNameLength) == 0) {
|
|
463
|
+
|
|
464
|
+
if (handle->dirw) {
|
|
465
|
+
/*
|
|
466
|
+
* We attempt to resolve the long form of the file name explicitly.
|
|
467
|
+
* We only do this for file names that might still exist on disk.
|
|
468
|
+
* If this fails, we use the name given by ReadDirectoryChangesW.
|
|
469
|
+
* This may be the long form or the 8.3 short name in some cases.
|
|
470
|
+
*/
|
|
471
|
+
if (file_info->Action != FILE_ACTION_REMOVED &&
|
|
472
|
+
file_info->Action != FILE_ACTION_RENAMED_OLD_NAME) {
|
|
473
|
+
/* Construct a full path to the file. */
|
|
474
|
+
size = wcslen(handle->dirw) +
|
|
475
|
+
file_info->FileNameLength / sizeof(WCHAR) + 2;
|
|
476
|
+
|
|
477
|
+
filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
|
|
478
|
+
if (!filenamew) {
|
|
479
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
_snwprintf(filenamew, size, L"%s\\%.*s", handle->dirw,
|
|
483
|
+
file_info->FileNameLength / (DWORD)sizeof(WCHAR),
|
|
484
|
+
file_info->FileName);
|
|
485
|
+
|
|
486
|
+
filenamew[size - 1] = L'\0';
|
|
487
|
+
|
|
488
|
+
/* Convert to long name. */
|
|
489
|
+
size = GetLongPathNameW(filenamew, NULL, 0);
|
|
490
|
+
|
|
491
|
+
if (size) {
|
|
492
|
+
long_filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
|
|
493
|
+
if (!long_filenamew) {
|
|
494
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
size = GetLongPathNameW(filenamew, long_filenamew, size);
|
|
498
|
+
if (size) {
|
|
499
|
+
long_filenamew[size] = '\0';
|
|
500
|
+
} else {
|
|
501
|
+
uv__free(long_filenamew);
|
|
502
|
+
long_filenamew = NULL;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
uv__free(filenamew);
|
|
507
|
+
|
|
508
|
+
if (long_filenamew) {
|
|
509
|
+
/* Get the file name out of the long path. */
|
|
510
|
+
uv__relative_path(long_filenamew,
|
|
511
|
+
handle->dirw,
|
|
512
|
+
&filenamew);
|
|
513
|
+
uv__free(long_filenamew);
|
|
514
|
+
long_filenamew = filenamew;
|
|
515
|
+
sizew = -1;
|
|
516
|
+
} else {
|
|
517
|
+
/* We couldn't get the long filename, use the one reported. */
|
|
518
|
+
filenamew = file_info->FileName;
|
|
519
|
+
sizew = file_info->FileNameLength / sizeof(WCHAR);
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
/*
|
|
523
|
+
* Removed or renamed events cannot be resolved to the long form.
|
|
524
|
+
* We therefore use the name given by ReadDirectoryChangesW.
|
|
525
|
+
* This may be the long form or the 8.3 short name in some cases.
|
|
526
|
+
*/
|
|
527
|
+
filenamew = file_info->FileName;
|
|
528
|
+
sizew = file_info->FileNameLength / sizeof(WCHAR);
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
/* We already have the long name of the file, so just use it. */
|
|
532
|
+
filenamew = handle->filew;
|
|
533
|
+
sizew = -1;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/* Convert the filename to utf8. */
|
|
537
|
+
uv__convert_utf16_to_utf8(filenamew, sizew, &filename);
|
|
538
|
+
|
|
539
|
+
switch (file_info->Action) {
|
|
540
|
+
case FILE_ACTION_ADDED:
|
|
541
|
+
case FILE_ACTION_REMOVED:
|
|
542
|
+
case FILE_ACTION_RENAMED_OLD_NAME:
|
|
543
|
+
case FILE_ACTION_RENAMED_NEW_NAME:
|
|
544
|
+
handle->cb(handle, filename, UV_RENAME, 0);
|
|
545
|
+
break;
|
|
546
|
+
|
|
547
|
+
case FILE_ACTION_MODIFIED:
|
|
548
|
+
handle->cb(handle, filename, UV_CHANGE, 0);
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
uv__free(filename);
|
|
553
|
+
filename = NULL;
|
|
554
|
+
uv__free(long_filenamew);
|
|
555
|
+
long_filenamew = NULL;
|
|
556
|
+
filenamew = NULL;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
offset = file_info->NextEntryOffset;
|
|
560
|
+
} while (offset && !(handle->flags & UV_HANDLE_CLOSING));
|
|
561
|
+
} else {
|
|
562
|
+
handle->cb(handle, NULL, UV_CHANGE, 0);
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
err = GET_REQ_ERROR(req);
|
|
566
|
+
/*
|
|
567
|
+
* Check whether the ERROR_ACCESS_DENIED is caused by the watched directory
|
|
568
|
+
* being actually deleted (not an actual error) or a legit error. Retrieve
|
|
569
|
+
* FileStandardInfo to check whether the directory is pending deletion.
|
|
570
|
+
*/
|
|
571
|
+
FILE_STANDARD_INFO info;
|
|
572
|
+
if (err == ERROR_ACCESS_DENIED &&
|
|
573
|
+
handle->dirw != NULL &&
|
|
574
|
+
GetFileInformationByHandleEx(handle->dir_handle,
|
|
575
|
+
FileStandardInfo,
|
|
576
|
+
&info,
|
|
577
|
+
sizeof(info)) &&
|
|
578
|
+
info.Directory &&
|
|
579
|
+
info.DeletePending) {
|
|
580
|
+
uv__convert_utf16_to_utf8(handle->dirw, -1, &filename);
|
|
581
|
+
handle->cb(handle, filename, UV_RENAME, 0);
|
|
582
|
+
uv__free(filename);
|
|
583
|
+
filename = NULL;
|
|
584
|
+
} else {
|
|
585
|
+
handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (handle->flags & UV_HANDLE_CLOSING) {
|
|
590
|
+
uv__want_endgame(loop, (uv_handle_t*)handle);
|
|
591
|
+
} else if (uv__is_active(handle)) {
|
|
592
|
+
uv__fs_event_queue_readdirchanges(loop, handle);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
void uv__fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle) {
|
|
598
|
+
uv_fs_event_stop(handle);
|
|
599
|
+
|
|
600
|
+
uv__handle_closing(handle);
|
|
601
|
+
|
|
602
|
+
if (!handle->req_pending) {
|
|
603
|
+
uv__want_endgame(loop, (uv_handle_t*)handle);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
void uv__fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle) {
|
|
610
|
+
if ((handle->flags & UV_HANDLE_CLOSING) && !handle->req_pending) {
|
|
611
|
+
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
|
612
|
+
|
|
613
|
+
if (handle->buffer) {
|
|
614
|
+
uv__free(handle->buffer);
|
|
615
|
+
handle->buffer = NULL;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
uv__handle_close(handle);
|
|
619
|
+
}
|
|
620
|
+
}
|