Skip to content

Commit 7272dbd

Browse files
committed
Upgrade libuv to 991f6ee
1 parent b5d58f1 commit 7272dbd

File tree

4 files changed

+141
-12
lines changed

4 files changed

+141
-12
lines changed

deps/uv/include/uv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ struct uv_fs_s {
890890
uv_fs_cb cb;
891891
ssize_t result;
892892
void* ptr;
893+
char* path;
893894
int errorno;
894895
UV_FS_PRIVATE_FIELDS
895896
};

deps/uv/src/unix/fs.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define ARGS4(a,b,c,d) (a), (b), (c), (d)
4141

4242
#define WRAP_EIO(type, eiofunc, func, args) \
43-
uv_fs_req_init(loop, req, type, cb); \
43+
uv_fs_req_init(loop, req, type, path, cb); \
4444
if (cb) { \
4545
/* async */ \
4646
uv_ref(loop); \
@@ -61,7 +61,7 @@
6161

6262

6363
static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
64-
uv_fs_cb cb) {
64+
char* path, uv_fs_cb cb) {
6565
/* Make sure the thread pool is initialized. */
6666
uv_eio_init(loop);
6767

@@ -72,12 +72,16 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
7272
req->cb = cb;
7373
req->result = 0;
7474
req->ptr = NULL;
75+
req->path = path ? strdup(path) : NULL;
7576
req->errorno = 0;
7677
req->eio = NULL;
7778
}
7879

7980

8081
void uv_fs_req_cleanup(uv_fs_t* req) {
82+
free(req->path);
83+
req->path = NULL;
84+
8185
switch (req->fs_type) {
8286
case UV_FS_READDIR:
8387
assert(req->ptr);
@@ -168,13 +172,14 @@ static int uv__fs_after(eio_req* eio) {
168172

169173

170174
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
175+
char* path = NULL;
171176
WRAP_EIO(UV_FS_CLOSE, eio_close, close, ARGS1(file));
172177
}
173178

174179

175180
int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
176181
int mode, uv_fs_cb cb) {
177-
uv_fs_req_init(loop, req, UV_FS_OPEN, cb);
182+
uv_fs_req_init(loop, req, UV_FS_OPEN, path, cb);
178183

179184
if (cb) {
180185
/* async */
@@ -202,7 +207,7 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
202207

203208
int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf,
204209
size_t length, off_t offset, uv_fs_cb cb) {
205-
uv_fs_req_init(loop, req, UV_FS_READ, cb);
210+
uv_fs_req_init(loop, req, UV_FS_READ, NULL, cb);
206211

207212
if (cb) {
208213
/* async */
@@ -238,7 +243,7 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
238243

239244
int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf,
240245
size_t length, off_t offset, uv_fs_cb cb) {
241-
uv_fs_req_init(loop, req, UV_FS_WRITE, cb);
246+
uv_fs_req_init(loop, req, UV_FS_WRITE, NULL, cb);
242247

243248
if (cb) {
244249
/* async */
@@ -284,7 +289,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
284289
size_t size = 0;
285290
size_t d_namlen = 0;
286291

287-
uv_fs_req_init(loop, req, UV_FS_READDIR, cb);
292+
uv_fs_req_init(loop, req, UV_FS_READDIR, path, cb);
288293

289294
if (cb) {
290295
/* async */
@@ -340,7 +345,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
340345
char* pathdup = path;
341346
int pathlen;
342347

343-
uv_fs_req_init(loop, req, UV_FS_STAT, cb);
348+
uv_fs_req_init(loop, req, UV_FS_STAT, path, cb);
344349

345350
/* TODO do this without duplicating the string. */
346351
/* TODO security */
@@ -383,7 +388,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
383388

384389

385390
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
386-
uv_fs_req_init(loop, req, UV_FS_FSTAT, cb);
391+
uv_fs_req_init(loop, req, UV_FS_FSTAT, NULL, cb);
387392

388393
if (cb) {
389394
/* async */
@@ -418,23 +423,27 @@ int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* ne
418423

419424

420425
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
426+
char* path = NULL;
421427
WRAP_EIO(UV_FS_FSYNC, eio_fsync, fsync, ARGS1(file))
422428
}
423429

424430

425431
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
432+
char* path = NULL;
426433
WRAP_EIO(UV_FS_FDATASYNC, eio_fdatasync, fdatasync, ARGS1(file))
427434
}
428435

429436

430437
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, off_t offset,
431438
uv_fs_cb cb) {
439+
char* path = NULL;
432440
WRAP_EIO(UV_FS_FTRUNCATE, eio_ftruncate, ftruncate, ARGS2(file, offset))
433441
}
434442

435443

436444
int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, uv_file in_fd,
437445
off_t in_offset, size_t length, uv_fs_cb cb) {
446+
char* path = NULL;
438447
WRAP_EIO(UV_FS_SENDFILE, eio_sendfile, eio_sendfile_sync,
439448
ARGS4(out_fd, in_fd, in_offset, length))
440449
}
@@ -471,7 +480,7 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
471480
char* pathdup = path;
472481
int pathlen;
473482

474-
uv_fs_req_init(loop, req, UV_FS_LSTAT, cb);
483+
uv_fs_req_init(loop, req, UV_FS_LSTAT, path, cb);
475484

476485
/* TODO do this without duplicating the string. */
477486
/* TODO security */
@@ -533,7 +542,7 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
533542

534543
status = -1;
535544

536-
uv_fs_req_init(loop, req, UV_FS_READLINK, cb);
545+
uv_fs_req_init(loop, req, UV_FS_READLINK, path, cb);
537546

538547
if (cb) {
539548
if ((req->eio = eio_readlink(path, EIO_PRI_DEFAULT, uv__fs_after, req))) {
@@ -581,6 +590,7 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
581590

582591
int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, int mode,
583592
uv_fs_cb cb) {
593+
char* path = NULL;
584594
WRAP_EIO(UV_FS_FCHMOD, eio_fchmod, fchmod, ARGS2(file, mode))
585595
}
586596

@@ -593,6 +603,7 @@ int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid,
593603

594604
int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid, int gid,
595605
uv_fs_cb cb) {
606+
char* path = NULL;
596607
WRAP_EIO(UV_FS_FCHOWN, eio_fchown, fchown, ARGS3(file, uid, gid))
597608
}
598609

deps/uv/src/win/fs.c

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void uv_fs_req_init_async(uv_loop_t* loop, uv_fs_t* req,
9797
req->cb = cb;
9898
req->result = 0;
9999
req->ptr = NULL;
100+
req->path = NULL; /* TODO https://github.com/joyent/libuv/issues/177 */
100101
req->errorno = 0;
101102
req->last_error = 0;
102103
memset(&req->overlapped, 0, sizeof(req->overlapped));
@@ -115,13 +116,120 @@ static void uv_fs_req_init_sync(uv_loop_t* loop, uv_fs_t* req,
115116
req->errorno = 0;
116117
}
117118

119+
/* this is where the CRT stores the current umask */
120+
extern int _umaskval;
118121

119122
void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
120-
int result = _open(path, flags, mode);
123+
DWORD access;
124+
DWORD share;
125+
SECURITY_ATTRIBUTES sa;
126+
DWORD disposition;
127+
DWORD attributes;
128+
HANDLE file;
129+
int result;
130+
131+
/* convert flags and mode to CreateFile parameters */
132+
switch (flags & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
133+
case _O_RDONLY:
134+
access = GENERIC_READ;
135+
break;
136+
case _O_WRONLY:
137+
access = GENERIC_WRITE;
138+
break;
139+
case _O_RDWR:
140+
access = GENERIC_READ | GENERIC_WRITE;
141+
break;
142+
default:
143+
result = -1;
144+
goto end;
145+
}
146+
147+
/*
148+
* Here is where we deviate significantly from what CRT's _open()
149+
* does. We indiscriminately use all the sharing modes, to match
150+
* UNIX semantics. In particular, this ensures that the file can
151+
* be deleted even whilst it's open, fixing issue #1449.
152+
*/
153+
share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
154+
155+
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
156+
sa.lpSecurityDescriptor = NULL;
157+
if (flags & _O_NOINHERIT) {
158+
sa.bInheritHandle = FALSE;
159+
} else {
160+
sa.bInheritHandle = TRUE;
161+
}
162+
163+
switch (flags & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
164+
case 0:
165+
case _O_EXCL:
166+
disposition = OPEN_EXISTING;
167+
break;
168+
case _O_CREAT:
169+
disposition = OPEN_ALWAYS;
170+
break;
171+
case _O_CREAT | _O_EXCL:
172+
case _O_CREAT | _O_TRUNC | _O_EXCL:
173+
disposition = CREATE_NEW;
174+
break;
175+
case _O_TRUNC:
176+
case _O_TRUNC | _O_EXCL:
177+
disposition = TRUNCATE_EXISTING;
178+
break;
179+
case _O_CREAT | _O_TRUNC:
180+
disposition = CREATE_ALWAYS;
181+
break;
182+
default:
183+
result = -1;
184+
goto end;
185+
}
186+
187+
attributes = FILE_ATTRIBUTE_NORMAL;
188+
if (flags & _O_CREAT) {
189+
if (!((mode & ~_umaskval) & _S_IWRITE)) {
190+
attributes |= FILE_ATTRIBUTE_READONLY;
191+
}
192+
}
193+
194+
if (flags & _O_TEMPORARY ) {
195+
attributes |= FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY;
196+
access |= DELETE;
197+
}
198+
199+
if (flags & _O_SHORT_LIVED) {
200+
attributes |= FILE_ATTRIBUTE_TEMPORARY;
201+
}
202+
203+
switch (flags & (_O_SEQUENTIAL | _O_RANDOM)) {
204+
case 0:
205+
break;
206+
case _O_SEQUENTIAL:
207+
attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
208+
break;
209+
case _O_RANDOM:
210+
attributes |= FILE_FLAG_RANDOM_ACCESS;
211+
break;
212+
default:
213+
result = -1;
214+
goto end;
215+
}
216+
217+
file = CreateFileA(path,
218+
access,
219+
share,
220+
&sa,
221+
disposition,
222+
attributes,
223+
NULL);
224+
if (file == INVALID_HANDLE_VALUE) {
225+
result = -1;
226+
goto end;
227+
}
228+
result = _open_osfhandle((intptr_t)file, flags);
229+
end:
121230
SET_REQ_RESULT(req, result);
122231
}
123232

124-
125233
void fs__close(uv_fs_t* req, uv_file file) {
126234
int result = _close(file);
127235
SET_REQ_RESULT(req, result);

deps/uv/test/test-fs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ static void open_cb(uv_fs_t* req) {
240240
ASSERT(0);
241241
}
242242
open_cb_count++;
243+
ASSERT(req->path);
244+
ASSERT(memcmp(req->path, "test_file2\0", 11) == 0);
243245
uv_fs_req_cleanup(req);
244246
memset(buf, 0, sizeof(buf));
245247
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
@@ -306,6 +308,8 @@ static void mkdir_cb(uv_fs_t* req) {
306308
ASSERT(req->fs_type == UV_FS_MKDIR);
307309
ASSERT(req->result != -1);
308310
mkdir_cb_count++;
311+
ASSERT(req->path);
312+
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
309313
uv_fs_req_cleanup(req);
310314
}
311315

@@ -315,6 +319,8 @@ static void rmdir_cb(uv_fs_t* req) {
315319
ASSERT(req->fs_type == UV_FS_RMDIR);
316320
ASSERT(req->result != -1);
317321
rmdir_cb_count++;
322+
ASSERT(req->path);
323+
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
318324
uv_fs_req_cleanup(req);
319325
}
320326

@@ -327,6 +333,8 @@ static void readdir_cb(uv_fs_t* req) {
327333
ASSERT(memcmp(req->ptr, "file1\0file2\0", 12) == 0
328334
|| memcmp(req->ptr, "file2\0file1\0", 12) == 0);
329335
readdir_cb_count++;
336+
ASSERT(req->path);
337+
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
330338
uv_fs_req_cleanup(req);
331339
ASSERT(!req->ptr);
332340
}
@@ -544,6 +552,7 @@ TEST_IMPL(fs_async_dir) {
544552
r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
545553
readdir_cb(&readdir_req);
546554

555+
547556
r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb);
548557
ASSERT(r == 0);
549558
uv_run(loop);

0 commit comments

Comments
 (0)