noderb 0.0.8 → 0.0.9

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.
Files changed (84) hide show
  1. data/ext/noderb_extension/extconf.rb +4 -2
  2. data/ext/noderb_extension/libuv/AUTHORS +2 -0
  3. data/ext/noderb_extension/libuv/Makefile +1 -1
  4. data/ext/noderb_extension/libuv/common.gypi +51 -51
  5. data/ext/noderb_extension/libuv/config-mingw.mk +3 -9
  6. data/ext/noderb_extension/libuv/config-unix.mk +10 -1
  7. data/ext/noderb_extension/libuv/include/uv-private/uv-unix.h +3 -2
  8. data/ext/noderb_extension/libuv/include/uv-private/uv-win.h +7 -6
  9. data/ext/noderb_extension/libuv/include/uv.h +47 -13
  10. data/ext/noderb_extension/libuv/src/ares/config_netbsd/ares_config.h +510 -0
  11. data/ext/noderb_extension/libuv/src/unix/core.c +20 -65
  12. data/ext/noderb_extension/libuv/src/unix/darwin.c +1 -0
  13. data/ext/noderb_extension/libuv/src/unix/eio/config_netbsd.h +81 -0
  14. data/ext/noderb_extension/libuv/src/unix/error.c +9 -1
  15. data/ext/noderb_extension/libuv/src/unix/ev/config_netbsd.h +120 -0
  16. data/ext/noderb_extension/libuv/src/unix/fs.c +151 -21
  17. data/ext/noderb_extension/libuv/src/unix/internal.h +30 -0
  18. data/ext/noderb_extension/libuv/src/unix/netbsd.c +68 -0
  19. data/ext/noderb_extension/libuv/src/unix/pipe.c +20 -30
  20. data/ext/noderb_extension/libuv/src/unix/process.c +13 -0
  21. data/ext/noderb_extension/libuv/src/unix/stream.c +105 -63
  22. data/ext/noderb_extension/libuv/src/unix/tcp.c +75 -21
  23. data/ext/noderb_extension/libuv/src/unix/tty.c +69 -0
  24. data/ext/noderb_extension/libuv/src/unix/udp.c +31 -0
  25. data/ext/noderb_extension/libuv/src/uv-common.c +2 -0
  26. data/ext/noderb_extension/libuv/src/uv-common.h +0 -6
  27. data/ext/noderb_extension/libuv/src/win/cares.c +7 -7
  28. data/ext/noderb_extension/libuv/src/win/core.c +25 -17
  29. data/ext/noderb_extension/libuv/src/win/error.c +7 -0
  30. data/ext/noderb_extension/libuv/src/win/fs.c +587 -92
  31. data/ext/noderb_extension/libuv/src/win/getaddrinfo.c +3 -1
  32. data/ext/noderb_extension/libuv/src/win/handle.c +0 -17
  33. data/ext/noderb_extension/libuv/src/win/internal.h +15 -5
  34. data/ext/noderb_extension/libuv/src/win/loop-watcher.c +1 -1
  35. data/ext/noderb_extension/libuv/src/win/pipe.c +6 -0
  36. data/ext/noderb_extension/libuv/src/win/process.c +90 -43
  37. data/ext/noderb_extension/libuv/src/win/tcp.c +37 -4
  38. data/ext/noderb_extension/libuv/src/win/threads.c +81 -0
  39. data/ext/noderb_extension/libuv/src/win/timer.c +15 -15
  40. data/ext/noderb_extension/libuv/src/win/tty.c +37 -0
  41. data/ext/noderb_extension/libuv/src/win/udp.c +8 -2
  42. data/ext/noderb_extension/libuv/src/win/winapi.c +12 -0
  43. data/ext/noderb_extension/libuv/src/win/winapi.h +1146 -1015
  44. data/ext/noderb_extension/libuv/test/benchmark-ares.c +0 -1
  45. data/ext/noderb_extension/libuv/test/benchmark-getaddrinfo.c +0 -1
  46. data/ext/noderb_extension/libuv/test/benchmark-ping-pongs.c +0 -1
  47. data/ext/noderb_extension/libuv/test/benchmark-pound.c +0 -1
  48. data/ext/noderb_extension/libuv/test/benchmark-pump.c +4 -6
  49. data/ext/noderb_extension/libuv/test/benchmark-spawn.c +0 -1
  50. data/ext/noderb_extension/libuv/test/benchmark-udp-packet-storm.c +0 -1
  51. data/ext/noderb_extension/libuv/test/dns-server.c +2 -2
  52. data/ext/noderb_extension/libuv/test/echo-server.c +4 -5
  53. data/ext/noderb_extension/libuv/test/run-tests.c +0 -2
  54. data/ext/noderb_extension/libuv/test/test-async.c +0 -2
  55. data/ext/noderb_extension/libuv/test/test-callback-stack.c +0 -2
  56. data/ext/noderb_extension/libuv/test/test-connection-fail.c +3 -5
  57. data/ext/noderb_extension/libuv/test/test-delayed-accept.c +2 -3
  58. data/ext/noderb_extension/libuv/test/test-fs.c +578 -42
  59. data/ext/noderb_extension/libuv/test/test-get-currentexe.c +12 -2
  60. data/ext/noderb_extension/libuv/test/test-getaddrinfo.c +10 -5
  61. data/ext/noderb_extension/libuv/test/test-gethostbyname.c +0 -2
  62. data/ext/noderb_extension/libuv/test/test-getsockname.c +92 -72
  63. data/ext/noderb_extension/libuv/test/test-idle.c +0 -3
  64. data/ext/noderb_extension/libuv/test/test-list.h +13 -0
  65. data/ext/noderb_extension/libuv/test/test-loop-handles.c +0 -3
  66. data/ext/noderb_extension/libuv/test/test-ping-pong.c +13 -19
  67. data/ext/noderb_extension/libuv/test/test-pipe-bind-error.c +0 -12
  68. data/ext/noderb_extension/libuv/test/test-ref.c +0 -7
  69. data/ext/noderb_extension/libuv/test/test-shutdown-eof.c +3 -3
  70. data/ext/noderb_extension/libuv/test/test-spawn.c +2 -11
  71. data/ext/noderb_extension/libuv/test/test-tcp-bind-error.c +0 -19
  72. data/ext/noderb_extension/libuv/test/test-tcp-bind6-error.c +0 -15
  73. data/ext/noderb_extension/libuv/test/test-tcp-close.c +129 -0
  74. data/ext/noderb_extension/libuv/test/test-tcp-writealot.c +0 -3
  75. data/ext/noderb_extension/libuv/test/test-threadpool.c +0 -2
  76. data/ext/noderb_extension/libuv/test/test-timer-again.c +0 -3
  77. data/ext/noderb_extension/libuv/test/test-timer.c +0 -2
  78. data/ext/noderb_extension/libuv/test/test-udp-dgram-too-big.c +0 -2
  79. data/ext/noderb_extension/libuv/test/test-udp-ipv6.c +0 -2
  80. data/ext/noderb_extension/libuv/test/test-udp-send-and-recv.c +0 -2
  81. data/ext/noderb_extension/libuv/uv.gyp +18 -2
  82. data/ext/noderb_extension/noderb_fs.c +1 -2
  83. data/lib/noderb/version.rb +1 -1
  84. metadata +10 -2
@@ -86,7 +86,6 @@ BENCHMARK_IMPL(gethostbyname) {
86
86
  return 1;
87
87
  }
88
88
 
89
- uv_init();
90
89
  loop = uv_default_loop();
91
90
 
92
91
  ares_callbacks = 0;
@@ -68,7 +68,6 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
68
68
  BENCHMARK_IMPL(getaddrinfo) {
69
69
  int i;
70
70
 
71
- uv_init(loop);
72
71
  loop = uv_default_loop();
73
72
 
74
73
  uv_update_time(loop);
@@ -200,7 +200,6 @@ static void pinger_new() {
200
200
 
201
201
 
202
202
  BENCHMARK_IMPL(ping_pongs) {
203
- uv_init();
204
203
  loop = uv_default_loop();
205
204
 
206
205
  start_time = uv_now(loop);
@@ -277,7 +277,6 @@ static int pound_it(int concurrency,
277
277
  uint64_t start_time; /* in ns */
278
278
  uint64_t end_time;
279
279
 
280
- uv_init();
281
280
  loop = uv_default_loop();
282
281
 
283
282
  uv_update_time(loop);
@@ -273,10 +273,12 @@ static void connection_cb(uv_stream_t* s, int status) {
273
273
 
274
274
  if (type == TCP) {
275
275
  stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
276
- uv_tcp_init(loop, (uv_tcp_t*)stream);
276
+ r = uv_tcp_init(loop, (uv_tcp_t*)stream);
277
+ ASSERT(r == 0);
277
278
  } else {
278
279
  stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t));
279
- uv_pipe_init(loop, (uv_pipe_t*)stream);
280
+ r = uv_pipe_init(loop, (uv_pipe_t*)stream);
281
+ ASSERT(r == 0);
280
282
  }
281
283
 
282
284
  r = uv_accept(s, stream);
@@ -367,7 +369,6 @@ HELPER_IMPL(tcp_pump_server) {
367
369
  int r;
368
370
 
369
371
  type = TCP;
370
- uv_init();
371
372
  loop = uv_default_loop();
372
373
 
373
374
  listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
@@ -391,7 +392,6 @@ HELPER_IMPL(pipe_pump_server) {
391
392
  int r;
392
393
  type = PIPE;
393
394
 
394
- uv_init();
395
395
  loop = uv_default_loop();
396
396
 
397
397
  /* Server */
@@ -414,7 +414,6 @@ void tcp_pump(int n) {
414
414
  TARGET_CONNECTIONS = n;
415
415
  type = TCP;
416
416
 
417
- uv_init();
418
417
  loop = uv_default_loop();
419
418
 
420
419
  connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
@@ -431,7 +430,6 @@ void pipe_pump(int n) {
431
430
  TARGET_CONNECTIONS = n;
432
431
  type = PIPE;
433
432
 
434
- uv_init();
435
433
  loop = uv_default_loop();
436
434
 
437
435
  /* Start making connections */
@@ -132,7 +132,6 @@ BENCHMARK_IMPL(spawn) {
132
132
  int r;
133
133
  static int64_t start_time, end_time;
134
134
 
135
- uv_init();
136
135
  loop = uv_default_loop();
137
136
 
138
137
  r = uv_exepath(exepath, &exepath_size);
@@ -134,7 +134,6 @@ static int do_packet_storm(int n_senders, int n_receivers) {
134
134
  ASSERT(n_senders <= MAX_SENDERS);
135
135
  ASSERT(n_receivers <= MAX_RECEIVERS);
136
136
 
137
- uv_init();
138
137
  loop = uv_default_loop();
139
138
 
140
139
  n_senders_ = n_senders;
@@ -272,7 +272,8 @@ static void on_connection(uv_stream_t* server, int status) {
272
272
  handle->state.prevbuf_pos = 0;
273
273
  handle->state.prevbuf_rem = 0;
274
274
 
275
- uv_tcp_init(loop, (uv_tcp_t*)handle);
275
+ r = uv_tcp_init(loop, (uv_tcp_t*)handle);
276
+ ASSERT(r == 0);
276
277
 
277
278
  r = uv_accept(server, (uv_stream_t*)handle);
278
279
  ASSERT(r == 0);
@@ -317,7 +318,6 @@ static int dns_start(int port) {
317
318
 
318
319
 
319
320
  HELPER_IMPL(dns_server) {
320
- uv_init();
321
321
  loop = uv_default_loop();
322
322
 
323
323
  if (dns_start(TEST_PORT_2))
@@ -144,13 +144,15 @@ static void on_connection(uv_stream_t* server, int status) {
144
144
  case TCP:
145
145
  stream = malloc(sizeof(uv_tcp_t));
146
146
  ASSERT(stream != NULL);
147
- uv_tcp_init(loop, (uv_tcp_t*)stream);
147
+ r = uv_tcp_init(loop, (uv_tcp_t*)stream);
148
+ ASSERT(r == 0);
148
149
  break;
149
150
 
150
151
  case PIPE:
151
152
  stream = malloc(sizeof(uv_pipe_t));
152
153
  ASSERT(stream != NULL);
153
- uv_pipe_init(loop, (uv_pipe_t*)stream);
154
+ r = uv_pipe_init(loop, (uv_pipe_t*)stream);
155
+ ASSERT(r == 0);
154
156
  break;
155
157
 
156
158
  default:
@@ -272,7 +274,6 @@ static int pipe_echo_start(char* pipeName) {
272
274
 
273
275
 
274
276
  HELPER_IMPL(tcp4_echo_server) {
275
- uv_init();
276
277
  loop = uv_default_loop();
277
278
 
278
279
  if (tcp4_echo_start(TEST_PORT))
@@ -284,7 +285,6 @@ HELPER_IMPL(tcp4_echo_server) {
284
285
 
285
286
 
286
287
  HELPER_IMPL(tcp6_echo_server) {
287
- uv_init();
288
288
  loop = uv_default_loop();
289
289
 
290
290
  if (tcp6_echo_start(TEST_PORT))
@@ -296,7 +296,6 @@ HELPER_IMPL(tcp6_echo_server) {
296
296
 
297
297
 
298
298
  HELPER_IMPL(pipe_echo_server) {
299
- uv_init();
300
299
  loop = uv_default_loop();
301
300
 
302
301
  if (pipe_echo_start(TEST_PIPENAME))
@@ -28,12 +28,10 @@
28
28
  /* Actual tests and helpers are defined in test-list.h */
29
29
  #include "test-list.h"
30
30
 
31
-
32
31
  /* The time in milliseconds after which a single test times out. */
33
32
  #define TEST_TIMEOUT 5000
34
33
 
35
34
  static int maybe_run_test(int argc, char **argv);
36
- static void list_all_tests(void);
37
35
 
38
36
 
39
37
  int main(int argc, char **argv) {
@@ -182,8 +182,6 @@ static void prepare_cb(uv_prepare_t* handle, int status) {
182
182
  TEST_IMPL(async) {
183
183
  int r;
184
184
 
185
- uv_init();
186
-
187
185
  r = uv_prepare_init(uv_default_loop(), &prepare_handle);
188
186
  ASSERT(r == 0);
189
187
  r = uv_prepare_start(&prepare_handle, prepare_cb);
@@ -176,8 +176,6 @@ static void connect_cb(uv_connect_t* req, int status) {
176
176
  TEST_IMPL(callback_stack) {
177
177
  struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
178
178
 
179
- uv_init();
180
-
181
179
  if (uv_tcp_init(uv_default_loop(), &client)) {
182
180
  FATAL("uv_tcp_init failed");
183
181
  }
@@ -119,8 +119,6 @@ void connection_fail(uv_connect_cb connect_cb) {
119
119
  * expect an error.
120
120
  */
121
121
  TEST_IMPL(connection_fail) {
122
- uv_init();
123
-
124
122
  connection_fail(on_connect_with_close);
125
123
 
126
124
  ASSERT(timer_close_cb_calls == 0);
@@ -136,10 +134,10 @@ TEST_IMPL(connection_fail) {
136
134
  * attempt.
137
135
  */
138
136
  TEST_IMPL(connection_fail_doesnt_auto_close) {
139
- uv_init();
140
-
137
+ int r;
141
138
 
142
- uv_timer_init(uv_default_loop(), &timer);
139
+ r = uv_timer_init(uv_default_loop(), &timer);
140
+ ASSERT(r == 0);
143
141
 
144
142
  connection_fail(on_connect_without_close);
145
143
 
@@ -57,7 +57,8 @@ static void do_accept(uv_timer_t* timer_handle, int status) {
57
57
  ASSERT(status == 0);
58
58
  ASSERT(accepted_handle != NULL);
59
59
 
60
- uv_tcp_init(uv_default_loop(), accepted_handle);
60
+ r = uv_tcp_init(uv_default_loop(), accepted_handle);
61
+ ASSERT(r == 0);
61
62
 
62
63
  /* Test to that uv_default_loop()->counters.tcp_init does not increase across the uv_accept. */
63
64
  tcpcnt = uv_default_loop()->counters.tcp_init;
@@ -180,8 +181,6 @@ static void client_connect() {
180
181
 
181
182
 
182
183
  TEST_IMPL(delayed_accept) {
183
- uv_init();
184
-
185
184
  start_server();
186
185
 
187
186
  client_connect();
@@ -25,23 +25,34 @@
25
25
  #include "uv.h"
26
26
  #include "task.h"
27
27
 
28
+ #include <errno.h>
28
29
  #include <string.h> /* memset */
29
30
  #include <fcntl.h>
30
31
  #include <sys/stat.h>
31
32
 
32
33
 
33
- #if !UNIX
34
+ #if UNIX
35
+ #include <unistd.h> /* unlink, rmdir, etc. */
36
+ #else
34
37
  # include <direct.h>
35
38
  # include <io.h>
36
39
  # define unlink _unlink
37
40
  # define rmdir _rmdir
38
- # define stat _stat
41
+ # define stat _stati64
39
42
  # define open _open
40
43
  # define write _write
41
44
  # define lseek _lseek
42
45
  # define close _close
43
46
  #endif
44
47
 
48
+
49
+ typedef struct {
50
+ const char* path;
51
+ double atime;
52
+ double mtime;
53
+ } utime_check_t;
54
+
55
+
45
56
  static int close_cb_count;
46
57
  static int create_cb_count;
47
58
  static int open_cb_count;
@@ -60,6 +71,13 @@ static int sendfile_cb_count;
60
71
  static int fstat_cb_count;
61
72
  static int chmod_cb_count;
62
73
  static int fchmod_cb_count;
74
+ static int chown_cb_count;
75
+ static int fchown_cb_count;
76
+ static int link_cb_count;
77
+ static int symlink_cb_count;
78
+ static int readlink_cb_count;
79
+ static int utime_cb_count;
80
+ static int futime_cb_count;
63
81
 
64
82
  static uv_loop_t* loop;
65
83
 
@@ -78,6 +96,8 @@ static uv_fs_t fsync_req;
78
96
  static uv_fs_t fdatasync_req;
79
97
  static uv_fs_t ftruncate_req;
80
98
  static uv_fs_t sendfile_req;
99
+ static uv_fs_t utime_req;
100
+ static uv_fs_t futime_req;
81
101
 
82
102
  static char buf[32];
83
103
  static char test_buf[] = "test-buffer\n";
@@ -93,18 +113,49 @@ void check_permission(const char* filename, int mode) {
93
113
  ASSERT(req.result == 0);
94
114
 
95
115
  s = req.ptr;
116
+ #ifdef _WIN32
117
+ /*
118
+ * On Windows, chmod can only modify S_IWUSR (_S_IWRITE) bit,
119
+ * so only testing for the specified flags.
120
+ */
121
+ ASSERT((s->st_mode & 0777) & mode);
122
+ #else
96
123
  ASSERT((s->st_mode & 0777) == mode);
124
+ #endif
97
125
 
98
126
  uv_fs_req_cleanup(&req);
99
127
  }
100
128
 
101
129
 
130
+ static void link_cb(uv_fs_t* req) {
131
+ ASSERT(req->fs_type == UV_FS_LINK);
132
+ ASSERT(req->result == 0);
133
+ link_cb_count++;
134
+ uv_fs_req_cleanup(req);
135
+ }
136
+
137
+
138
+ static void symlink_cb(uv_fs_t* req) {
139
+ ASSERT(req->fs_type == UV_FS_SYMLINK);
140
+ ASSERT(req->result == 0);
141
+ symlink_cb_count++;
142
+ uv_fs_req_cleanup(req);
143
+ }
144
+
145
+ static void readlink_cb(uv_fs_t* req) {
146
+ ASSERT(req->fs_type == UV_FS_READLINK);
147
+ ASSERT(req->result == 0);
148
+ ASSERT(strcmp(req->ptr, "test_file_symlink2") == 0);
149
+ readlink_cb_count++;
150
+ uv_fs_req_cleanup(req);
151
+ }
152
+
102
153
  static void fchmod_cb(uv_fs_t* req) {
103
154
  ASSERT(req->fs_type == UV_FS_FCHMOD);
104
155
  ASSERT(req->result == 0);
105
156
  fchmod_cb_count++;
106
157
  uv_fs_req_cleanup(req);
107
- check_permission("test_file", 0600);
158
+ check_permission("test_file", (int)req->data);
108
159
  }
109
160
 
110
161
 
@@ -113,7 +164,23 @@ static void chmod_cb(uv_fs_t* req) {
113
164
  ASSERT(req->result == 0);
114
165
  chmod_cb_count++;
115
166
  uv_fs_req_cleanup(req);
116
- check_permission("test_file", 0200);
167
+ check_permission("test_file", (int)req->data);
168
+ }
169
+
170
+
171
+ static void fchown_cb(uv_fs_t* req) {
172
+ ASSERT(req->fs_type == UV_FS_FCHOWN);
173
+ ASSERT(req->result == 0);
174
+ fchown_cb_count++;
175
+ uv_fs_req_cleanup(req);
176
+ }
177
+
178
+
179
+ static void chown_cb(uv_fs_t* req) {
180
+ ASSERT(req->fs_type == UV_FS_CHOWN);
181
+ ASSERT(req->result == 0);
182
+ chown_cb_count++;
183
+ uv_fs_req_cleanup(req);
117
184
  }
118
185
 
119
186
 
@@ -187,6 +254,8 @@ static void open_cb(uv_fs_t* req) {
187
254
  ASSERT(0);
188
255
  }
189
256
  open_cb_count++;
257
+ ASSERT(req->path);
258
+ ASSERT(memcmp(req->path, "test_file2\0", 11) == 0);
190
259
  uv_fs_req_cleanup(req);
191
260
  memset(buf, 0, sizeof(buf));
192
261
  r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
@@ -253,6 +322,8 @@ static void mkdir_cb(uv_fs_t* req) {
253
322
  ASSERT(req->fs_type == UV_FS_MKDIR);
254
323
  ASSERT(req->result != -1);
255
324
  mkdir_cb_count++;
325
+ ASSERT(req->path);
326
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
256
327
  uv_fs_req_cleanup(req);
257
328
  }
258
329
 
@@ -262,6 +333,8 @@ static void rmdir_cb(uv_fs_t* req) {
262
333
  ASSERT(req->fs_type == UV_FS_RMDIR);
263
334
  ASSERT(req->result != -1);
264
335
  rmdir_cb_count++;
336
+ ASSERT(req->path);
337
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
265
338
  uv_fs_req_cleanup(req);
266
339
  }
267
340
 
@@ -271,10 +344,11 @@ static void readdir_cb(uv_fs_t* req) {
271
344
  ASSERT(req->fs_type == UV_FS_READDIR);
272
345
  ASSERT(req->result == 2);
273
346
  ASSERT(req->ptr);
274
- ASSERT(strcmp((const char*)req->ptr, "file1") == 0);
275
- ASSERT(strcmp((char*)req->ptr + strlen((const char*)req->ptr) + 1,
276
- "file2") == 0);
347
+ ASSERT(memcmp(req->ptr, "file1\0file2\0", 12) == 0
348
+ || memcmp(req->ptr, "file2\0file1\0", 12) == 0);
277
349
  readdir_cb_count++;
350
+ ASSERT(req->path);
351
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
278
352
  uv_fs_req_cleanup(req);
279
353
  ASSERT(!req->ptr);
280
354
  }
@@ -300,6 +374,100 @@ static void sendfile_cb(uv_fs_t* req) {
300
374
  }
301
375
 
302
376
 
377
+ static void open_noent_cb(uv_fs_t* req) {
378
+ ASSERT(req->fs_type == UV_FS_OPEN);
379
+ ASSERT(req->errorno == UV_ENOENT);
380
+ ASSERT(req->result == -1);
381
+ open_cb_count++;
382
+ uv_fs_req_cleanup(req);
383
+ }
384
+
385
+
386
+ TEST_IMPL(fs_file_noent) {
387
+ uv_fs_t req;
388
+ int r;
389
+
390
+ loop = uv_default_loop();
391
+
392
+ r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
393
+ ASSERT(r == -1);
394
+ ASSERT(req.result == -1);
395
+ ASSERT(uv_last_error(loop).code == UV_ENOENT);
396
+ uv_fs_req_cleanup(&req);
397
+
398
+ r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
399
+ ASSERT(r == 0);
400
+
401
+ ASSERT(open_cb_count == 0);
402
+ uv_run(loop);
403
+ ASSERT(open_cb_count == 1);
404
+
405
+ /* TODO add EACCES test */
406
+
407
+ return 0;
408
+ }
409
+
410
+
411
+ static void check_utime(const char* path, double atime, double mtime) {
412
+ struct stat* s;
413
+ uv_fs_t req;
414
+ int r;
415
+
416
+ r = uv_fs_stat(loop, &req, path, NULL);
417
+ ASSERT(r == 0);
418
+
419
+ ASSERT(req.result == 0);
420
+ s = req.ptr;
421
+
422
+ #if _WIN32
423
+ ASSERT(s->st_atime == atime);
424
+ ASSERT(s->st_mtime == mtime);
425
+ #elif !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
426
+ ASSERT(s->st_atimespec.tv_sec == atime);
427
+ ASSERT(s->st_atimespec.tv_nsec == 0); /* FIXME check sub-second precision */
428
+ ASSERT(s->st_mtimespec.tv_sec == mtime);
429
+ ASSERT(s->st_mtimespec.tv_nsec == 0); /* FIXME check sub-second precision */
430
+ #else
431
+ ASSERT(s->st_atim.tv_sec == atime);
432
+ ASSERT(s->st_atim.tv_nsec == 0); /* FIXME check sub-second precision */
433
+ ASSERT(s->st_mtim.tv_sec == mtime);
434
+ ASSERT(s->st_mtim.tv_nsec == 0); /* FIXME check sub-second precision */
435
+ #endif
436
+
437
+ uv_fs_req_cleanup(&req);
438
+ }
439
+
440
+
441
+ static void utime_cb(uv_fs_t* req) {
442
+ utime_check_t* c;
443
+
444
+ ASSERT(req == &utime_req);
445
+ ASSERT(req->result == 0);
446
+ ASSERT(req->fs_type == UV_FS_UTIME);
447
+
448
+ c = req->data;
449
+ check_utime(c->path, c->atime, c->mtime);
450
+
451
+ uv_fs_req_cleanup(req);
452
+ utime_cb_count++;
453
+ }
454
+
455
+
456
+ static void futime_cb(uv_fs_t* req) {
457
+ utime_check_t* c;
458
+
459
+ ASSERT(req == &futime_req);
460
+ ASSERT(req->result == 0);
461
+ ASSERT(req->fs_type == UV_FS_FUTIME);
462
+
463
+ c = req->data;
464
+ check_utime(c->path, c->atime, c->mtime);
465
+
466
+ uv_fs_req_cleanup(req);
467
+ futime_cb_count++;
468
+ }
469
+
470
+
303
471
  TEST_IMPL(fs_file_async) {
304
472
  int r;
305
473
 
@@ -307,7 +475,6 @@ TEST_IMPL(fs_file_async) {
307
475
  unlink("test_file");
308
476
  unlink("test_file2");
309
477
 
310
- uv_init();
311
478
  loop = uv_default_loop();
312
479
 
313
480
  r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
@@ -370,73 +537,72 @@ TEST_IMPL(fs_file_sync) {
370
537
  unlink("test_file");
371
538
  unlink("test_file2");
372
539
 
373
- uv_init();
374
540
  loop = uv_default_loop();
375
541
 
376
542
  r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
377
543
  S_IWRITE | S_IREAD, NULL);
378
- ASSERT(r == 0);
544
+ ASSERT(r != -1);
379
545
  ASSERT(open_req1.result != -1);
380
546
  uv_fs_req_cleanup(&open_req1);
381
547
 
382
548
  r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
383
549
  sizeof(test_buf), -1, NULL);
384
- ASSERT(r == 0);
550
+ ASSERT(r != -1);
385
551
  ASSERT(write_req.result != -1);
386
552
  uv_fs_req_cleanup(&write_req);
387
553
 
388
554
  r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
389
- ASSERT(r == 0);
555
+ ASSERT(r != -1);
390
556
  ASSERT(close_req.result != -1);
391
557
  uv_fs_req_cleanup(&close_req);
392
558
 
393
559
  r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
394
- ASSERT(r == 0);
560
+ ASSERT(r != -1);
395
561
  ASSERT(open_req1.result != -1);
396
562
  uv_fs_req_cleanup(&open_req1);
397
563
 
398
564
  r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
399
565
  NULL);
400
- ASSERT(r == 0);
566
+ ASSERT(r != -1);
401
567
  ASSERT(read_req.result != -1);
402
568
  ASSERT(strcmp(buf, test_buf) == 0);
403
569
  uv_fs_req_cleanup(&read_req);
404
570
 
405
571
  r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL);
406
- ASSERT(r == 0);
572
+ ASSERT(r != -1);
407
573
  ASSERT(ftruncate_req.result != -1);
408
574
  uv_fs_req_cleanup(&ftruncate_req);
409
575
 
410
576
  r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
411
- ASSERT(r == 0);
577
+ ASSERT(r != -1);
412
578
  ASSERT(close_req.result != -1);
413
579
  uv_fs_req_cleanup(&close_req);
414
580
 
415
581
  r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
416
- ASSERT(r == 0);
582
+ ASSERT(r != -1);
417
583
  ASSERT(rename_req.result != -1);
418
584
  uv_fs_req_cleanup(&rename_req);
419
585
 
420
586
  r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
421
- ASSERT(r == 0);
587
+ ASSERT(r != -1);
422
588
  ASSERT(open_req1.result != -1);
423
589
  uv_fs_req_cleanup(&open_req1);
424
590
 
425
591
  memset(buf, 0, sizeof(buf));
426
592
  r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
427
593
  NULL);
428
- ASSERT(r == 0);
594
+ ASSERT(r != -1);
429
595
  ASSERT(read_req.result != -1);
430
596
  ASSERT(strcmp(buf, "test-bu") == 0);
431
597
  uv_fs_req_cleanup(&read_req);
432
598
 
433
599
  r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
434
- ASSERT(r == 0);
600
+ ASSERT(r != -1);
435
601
  ASSERT(close_req.result != -1);
436
602
  uv_fs_req_cleanup(&close_req);
437
603
 
438
604
  r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL);
439
- ASSERT(r == 0);
605
+ ASSERT(r != -1);
440
606
  ASSERT(unlink_req.result != -1);
441
607
  uv_fs_req_cleanup(&unlink_req);
442
608
 
@@ -456,7 +622,6 @@ TEST_IMPL(fs_async_dir) {
456
622
  unlink("test_dir/file2");
457
623
  rmdir("test_dir");
458
624
 
459
- uv_init();
460
625
  loop = uv_default_loop();
461
626
 
462
627
  r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb);
@@ -468,7 +633,7 @@ TEST_IMPL(fs_async_dir) {
468
633
  /* Create 2 files synchronously. */
469
634
  r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
470
635
  S_IWRITE | S_IREAD, NULL);
471
- ASSERT(r == 0);
636
+ ASSERT(r != -1);
472
637
  uv_fs_req_cleanup(&open_req1);
473
638
  r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
474
639
  ASSERT(r == 0);
@@ -476,7 +641,7 @@ TEST_IMPL(fs_async_dir) {
476
641
 
477
642
  r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
478
643
  S_IWRITE | S_IREAD, NULL);
479
- ASSERT(r == 0);
644
+ ASSERT(r != -1);
480
645
  uv_fs_req_cleanup(&open_req1);
481
646
  r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
482
647
  ASSERT(r == 0);
@@ -488,6 +653,16 @@ TEST_IMPL(fs_async_dir) {
488
653
  uv_run(loop);
489
654
  ASSERT(readdir_cb_count == 1);
490
655
 
656
+ /* sync uv_fs_readdir */
657
+ r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
658
+ ASSERT(r == 2);
659
+ ASSERT(readdir_req.result == 2);
660
+ ASSERT(readdir_req.ptr);
661
+ ASSERT(memcmp(readdir_req.ptr, "file1\0file2\0", 12) == 0
662
+ || memcmp(readdir_req.ptr, "file2\0file1\0", 12) == 0);
663
+ uv_fs_req_cleanup(&readdir_req);
664
+ ASSERT(!readdir_req.ptr);
665
+
491
666
  r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb);
492
667
  ASSERT(r == 0);
493
668
  uv_run(loop);
@@ -534,8 +709,9 @@ TEST_IMPL(fs_async_sendfile) {
534
709
  int f, r;
535
710
  struct stat s1, s2;
536
711
 
712
+ loop = uv_default_loop();
713
+
537
714
  /* Setup. */
538
- uv_init();
539
715
  unlink("test_file");
540
716
  unlink("test_file2");
541
717
 
@@ -555,16 +731,14 @@ TEST_IMPL(fs_async_sendfile) {
555
731
  ASSERT(r == 0);
556
732
 
557
733
  /* Test starts here. */
558
- loop = uv_default_loop();
559
-
560
734
  r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
561
- ASSERT(r == 0);
735
+ ASSERT(r != -1);
562
736
  ASSERT(open_req1.result != -1);
563
737
  uv_fs_req_cleanup(&open_req1);
564
738
 
565
739
  r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT,
566
740
  S_IWRITE | S_IREAD, NULL);
567
- ASSERT(r == 0);
741
+ ASSERT(r != -1);
568
742
  ASSERT(open_req2.result != -1);
569
743
  uv_fs_req_cleanup(&open_req2);
570
744
 
@@ -598,29 +772,29 @@ TEST_IMPL(fs_fstat) {
598
772
  int r;
599
773
  uv_fs_t req;
600
774
  uv_file file;
775
+ struct stat* s;
601
776
 
602
777
  /* Setup. */
603
778
  unlink("test_file");
604
779
 
605
- uv_init();
606
-
607
780
  loop = uv_default_loop();
608
781
 
609
- r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, 0, NULL);
610
- ASSERT(r == 0);
782
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
783
+ S_IWRITE | S_IREAD, NULL);
784
+ ASSERT(r != -1);
611
785
  ASSERT(req.result != -1);
612
786
  file = req.result;
613
787
  uv_fs_req_cleanup(&req);
614
788
 
615
789
  r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
616
- ASSERT(r == 0);
790
+ ASSERT(r == sizeof(test_buf));
617
791
  ASSERT(req.result == sizeof(test_buf));
618
792
  uv_fs_req_cleanup(&req);
619
793
 
620
794
  r = uv_fs_fstat(loop, &req, file, NULL);
621
795
  ASSERT(r == 0);
622
796
  ASSERT(req.result == 0);
623
- struct stat* s = req.ptr;
797
+ s = req.ptr;
624
798
  ASSERT(s->st_size == sizeof(test_buf));
625
799
  uv_fs_req_cleanup(&req);
626
800
 
@@ -637,7 +811,7 @@ TEST_IMPL(fs_fstat) {
637
811
  uv_fs_req_cleanup(&req);
638
812
 
639
813
  /*
640
- * Run the loop just to check we don't have make any extranious uv_ref()
814
+ * Run the loop just to check we don't have make any extraneous uv_ref()
641
815
  * calls. This should drop out immediately.
642
816
  */
643
817
  uv_run(loop);
@@ -657,21 +831,21 @@ TEST_IMPL(fs_chmod) {
657
831
  /* Setup. */
658
832
  unlink("test_file");
659
833
 
660
- uv_init();
661
-
662
834
  loop = uv_default_loop();
663
835
 
664
- r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, 0, NULL);
665
- ASSERT(r == 0);
836
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
837
+ S_IWRITE | S_IREAD, NULL);
838
+ ASSERT(r != -1);
666
839
  ASSERT(req.result != -1);
667
840
  file = req.result;
668
841
  uv_fs_req_cleanup(&req);
669
842
 
670
843
  r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
671
- ASSERT(r == 0);
844
+ ASSERT(r == sizeof(test_buf));
672
845
  ASSERT(req.result == sizeof(test_buf));
673
846
  uv_fs_req_cleanup(&req);
674
847
 
848
+ #ifndef _WIN32
675
849
  /* Make the file write-only */
676
850
  r = uv_fs_chmod(loop, &req, "test_file", 0200, NULL);
677
851
  ASSERT(r == 0);
@@ -679,6 +853,15 @@ TEST_IMPL(fs_chmod) {
679
853
  uv_fs_req_cleanup(&req);
680
854
 
681
855
  check_permission("test_file", 0200);
856
+ #endif
857
+
858
+ /* Make the file read-only */
859
+ r = uv_fs_chmod(loop, &req, "test_file", 0400, NULL);
860
+ ASSERT(r == 0);
861
+ ASSERT(req.result == 0);
862
+ uv_fs_req_cleanup(&req);
863
+
864
+ check_permission("test_file", 0400);
682
865
 
683
866
  /* Make the file read+write with sync uv_fs_fchmod */
684
867
  r = uv_fs_fchmod(loop, &req, file, 0600, NULL);
@@ -688,13 +871,25 @@ TEST_IMPL(fs_chmod) {
688
871
 
689
872
  check_permission("test_file", 0600);
690
873
 
874
+ #ifndef _WIN32
691
875
  /* async chmod */
876
+ req.data = (void*)0200;
692
877
  r = uv_fs_chmod(loop, &req, "test_file", 0200, chmod_cb);
693
878
  ASSERT(r == 0);
694
879
  uv_run(loop);
695
880
  ASSERT(chmod_cb_count == 1);
881
+ chmod_cb_count = 0; /* reset for the next test */
882
+ #endif
883
+
884
+ /* async chmod */
885
+ req.data = (void*)0400;
886
+ r = uv_fs_chmod(loop, &req, "test_file", 0400, chmod_cb);
887
+ ASSERT(r == 0);
888
+ uv_run(loop);
889
+ ASSERT(chmod_cb_count == 1);
696
890
 
697
891
  /* async fchmod */
892
+ req.data = (void*)0600;
698
893
  r = uv_fs_fchmod(loop, &req, file, 0600, fchmod_cb);
699
894
  ASSERT(r == 0);
700
895
  uv_run(loop);
@@ -703,13 +898,354 @@ TEST_IMPL(fs_chmod) {
703
898
  close(file);
704
899
 
705
900
  /*
706
- * Run the loop just to check we don't have make any extranious uv_ref()
901
+ * Run the loop just to check we don't have make any extraneous uv_ref()
902
+ * calls. This should drop out immediately.
903
+ */
904
+ uv_run(loop);
905
+
906
+ /* Cleanup. */
907
+ unlink("test_file");
908
+
909
+ return 0;
910
+ }
911
+
912
+
913
+ TEST_IMPL(fs_chown) {
914
+ int r;
915
+ uv_fs_t req;
916
+ uv_file file;
917
+
918
+ /* Setup. */
919
+ unlink("test_file");
920
+
921
+ loop = uv_default_loop();
922
+
923
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
924
+ S_IWRITE | S_IREAD, NULL);
925
+ ASSERT(r != -1);
926
+ ASSERT(req.result != -1);
927
+ file = req.result;
928
+ uv_fs_req_cleanup(&req);
929
+
930
+ /* sync chown */
931
+ r = uv_fs_chown(loop, &req, "test_file", -1, -1, NULL);
932
+ ASSERT(r == 0);
933
+ ASSERT(req.result == 0);
934
+ uv_fs_req_cleanup(&req);
935
+
936
+ /* sync fchown */
937
+ r = uv_fs_fchown(loop, &req, file, -1, -1, NULL);
938
+ ASSERT(r == 0);
939
+ ASSERT(req.result == 0);
940
+ uv_fs_req_cleanup(&req);
941
+
942
+ /* async chown */
943
+ r = uv_fs_chown(loop, &req, "test_file", -1, -1, chown_cb);
944
+ ASSERT(r == 0);
945
+ uv_run(loop);
946
+ ASSERT(chown_cb_count == 1);
947
+
948
+ /* async fchown */
949
+ r = uv_fs_fchown(loop, &req, file, -1, -1, fchown_cb);
950
+ ASSERT(r == 0);
951
+ uv_run(loop);
952
+ ASSERT(fchown_cb_count == 1);
953
+
954
+ close(file);
955
+
956
+ /*
957
+ * Run the loop just to check we don't have make any extraneous uv_ref()
958
+ * calls. This should drop out immediately.
959
+ */
960
+ uv_run(loop);
961
+
962
+ /* Cleanup. */
963
+ unlink("test_file");
964
+
965
+ return 0;
966
+ }
967
+
968
+
969
+ TEST_IMPL(fs_link) {
970
+ int r;
971
+ uv_fs_t req;
972
+ uv_file file;
973
+ uv_file link;
974
+
975
+ /* Setup. */
976
+ unlink("test_file");
977
+ unlink("test_file_link");
978
+ unlink("test_file_link2");
979
+
980
+ loop = uv_default_loop();
981
+
982
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
983
+ S_IWRITE | S_IREAD, NULL);
984
+ ASSERT(r != -1);
985
+ ASSERT(req.result != -1);
986
+ file = req.result;
987
+ uv_fs_req_cleanup(&req);
988
+
989
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
990
+ ASSERT(r == sizeof(test_buf));
991
+ ASSERT(req.result == sizeof(test_buf));
992
+ uv_fs_req_cleanup(&req);
993
+
994
+ close(file);
995
+
996
+ /* sync link */
997
+ r = uv_fs_link(loop, &req, "test_file", "test_file_link", NULL);
998
+ ASSERT(r == 0);
999
+ ASSERT(req.result == 0);
1000
+ uv_fs_req_cleanup(&req);
1001
+
1002
+ r = uv_fs_open(loop, &req, "test_file_link", O_RDWR, 0, NULL);
1003
+ ASSERT(r != -1);
1004
+ ASSERT(req.result != -1);
1005
+ link = req.result;
1006
+ uv_fs_req_cleanup(&req);
1007
+
1008
+ memset(buf, 0, sizeof(buf));
1009
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1010
+ ASSERT(r != -1);
1011
+ ASSERT(req.result != -1);
1012
+ ASSERT(strcmp(buf, test_buf) == 0);
1013
+
1014
+ close(link);
1015
+
1016
+ /* async link */
1017
+ r = uv_fs_link(loop, &req, "test_file", "test_file_link2", link_cb);
1018
+ ASSERT(r == 0);
1019
+ uv_run(loop);
1020
+ ASSERT(link_cb_count == 1);
1021
+
1022
+ r = uv_fs_open(loop, &req, "test_file_link2", O_RDWR, 0, NULL);
1023
+ ASSERT(r != -1);
1024
+ ASSERT(req.result != -1);
1025
+ link = req.result;
1026
+ uv_fs_req_cleanup(&req);
1027
+
1028
+ memset(buf, 0, sizeof(buf));
1029
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1030
+ ASSERT(r != -1);
1031
+ ASSERT(req.result != -1);
1032
+ ASSERT(strcmp(buf, test_buf) == 0);
1033
+
1034
+ close(link);
1035
+
1036
+ /*
1037
+ * Run the loop just to check we don't have make any extraneous uv_ref()
1038
+ * calls. This should drop out immediately.
1039
+ */
1040
+ uv_run(loop);
1041
+
1042
+ /* Cleanup. */
1043
+ unlink("test_file");
1044
+ unlink("test_file_link");
1045
+ unlink("test_file_link2");
1046
+
1047
+ return 0;
1048
+ }
1049
+
1050
+
1051
+ TEST_IMPL(fs_symlink) {
1052
+ int r;
1053
+ uv_fs_t req;
1054
+ uv_file file;
1055
+ uv_file link;
1056
+
1057
+ /* Setup. */
1058
+ unlink("test_file");
1059
+ unlink("test_file_symlink");
1060
+ unlink("test_file_symlink2");
1061
+ unlink("test_file_symlink_symlink");
1062
+ unlink("test_file_symlink2_symlink");
1063
+
1064
+ loop = uv_default_loop();
1065
+
1066
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
1067
+ S_IWRITE | S_IREAD, NULL);
1068
+ ASSERT(r != -1);
1069
+ ASSERT(req.result != -1);
1070
+ file = req.result;
1071
+ uv_fs_req_cleanup(&req);
1072
+
1073
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
1074
+ ASSERT(r == sizeof(test_buf));
1075
+ ASSERT(req.result == sizeof(test_buf));
1076
+ uv_fs_req_cleanup(&req);
1077
+
1078
+ close(file);
1079
+
1080
+ /* sync symlink */
1081
+ r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink", 0, NULL);
1082
+ #ifdef _WIN32
1083
+ if (r == -1) {
1084
+ if (req.errorno == ENOSYS) {
1085
+ /*
1086
+ * Windows doesn't support symlinks on older versions.
1087
+ * We just pass the test and bail out early if we get ENOTSUP.
1088
+ */
1089
+ return 0;
1090
+ } else if (uv_last_error(loop).sys_errno_ == ERROR_PRIVILEGE_NOT_HELD) {
1091
+ /*
1092
+ * Creating a symlink is only allowed when running elevated.
1093
+ * We pass the test and bail out early if we get ERROR_PRIVILEGE_NOT_HELD.
1094
+ */
1095
+ return 0;
1096
+ }
1097
+ }
1098
+ #endif
1099
+ ASSERT(r == 0);
1100
+ ASSERT(req.result == 0);
1101
+ uv_fs_req_cleanup(&req);
1102
+
1103
+ r = uv_fs_open(loop, &req, "test_file_symlink", O_RDWR, 0, NULL);
1104
+ ASSERT(r != -1);
1105
+ ASSERT(req.result != -1);
1106
+ link = req.result;
1107
+ uv_fs_req_cleanup(&req);
1108
+
1109
+ memset(buf, 0, sizeof(buf));
1110
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1111
+ ASSERT(r != -1);
1112
+ ASSERT(req.result != -1);
1113
+ ASSERT(strcmp(buf, test_buf) == 0);
1114
+
1115
+ close(link);
1116
+
1117
+ r = uv_fs_symlink(loop, &req, "test_file_symlink", "test_file_symlink_symlink", 0, NULL);
1118
+ ASSERT(r != -1);
1119
+ r = uv_fs_readlink(loop, &req, "test_file_symlink_symlink", NULL);
1120
+ ASSERT(r != -1);
1121
+ ASSERT(strcmp(req.ptr, "test_file_symlink") == 0);
1122
+ uv_fs_req_cleanup(&req);
1123
+
1124
+ /* async link */
1125
+ r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink2", 0, symlink_cb);
1126
+ ASSERT(r == 0);
1127
+ uv_run(loop);
1128
+ ASSERT(symlink_cb_count == 1);
1129
+
1130
+ r = uv_fs_open(loop, &req, "test_file_symlink2", O_RDWR, 0, NULL);
1131
+ ASSERT(r != -1);
1132
+ ASSERT(req.result != -1);
1133
+ link = req.result;
1134
+ uv_fs_req_cleanup(&req);
1135
+
1136
+ memset(buf, 0, sizeof(buf));
1137
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1138
+ ASSERT(r != -1);
1139
+ ASSERT(req.result != -1);
1140
+ ASSERT(strcmp(buf, test_buf) == 0);
1141
+
1142
+ close(link);
1143
+
1144
+ r = uv_fs_symlink(loop, &req, "test_file_symlink2", "test_file_symlink2_symlink", 0, NULL);
1145
+ ASSERT(r != -1);
1146
+ r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb);
1147
+ ASSERT(r != -1);
1148
+ uv_run(loop);
1149
+ ASSERT(readlink_cb_count == 1);
1150
+
1151
+ /*
1152
+ * Run the loop just to check we don't have make any extraneous uv_ref()
707
1153
  * calls. This should drop out immediately.
708
1154
  */
709
1155
  uv_run(loop);
710
1156
 
711
1157
  /* Cleanup. */
712
1158
  unlink("test_file");
1159
+ unlink("test_file_symlink");
1160
+ unlink("test_file_symlink_symlink");
1161
+ unlink("test_file_symlink2");
1162
+ unlink("test_file_symlink2_symlink");
1163
+
1164
+ return 0;
1165
+ }
1166
+
1167
+
1168
+ TEST_IMPL(fs_utime) {
1169
+ utime_check_t checkme;
1170
+ const char* path = ".";
1171
+ double atime;
1172
+ double mtime;
1173
+ uv_fs_t req;
1174
+ int r;
1175
+
1176
+ loop = uv_default_loop();
1177
+
1178
+ atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
1179
+
1180
+ r = uv_fs_utime(loop, &req, path, atime, mtime, NULL);
1181
+ ASSERT(r == 0);
1182
+ ASSERT(req.result == 0);
1183
+ uv_fs_req_cleanup(&req);
1184
+
1185
+ r = uv_fs_stat(loop, &req, path, NULL);
1186
+ ASSERT(r == 0);
1187
+ ASSERT(req.result == 0);
1188
+ check_utime(path, atime, mtime);
1189
+ uv_fs_req_cleanup(&req);
1190
+
1191
+ atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
1192
+ checkme.path = path;
1193
+ checkme.atime = atime;
1194
+ checkme.mtime = mtime;
1195
+
1196
+ /* async utime */
1197
+ utime_req.data = &checkme;
1198
+ r = uv_fs_utime(loop, &utime_req, path, atime, mtime, utime_cb);
1199
+ ASSERT(r == 0);
1200
+ uv_run(loop);
1201
+ ASSERT(utime_cb_count == 1);
1202
+
1203
+ return 0;
1204
+ }
1205
+
1206
+
1207
+ TEST_IMPL(fs_futime) {
1208
+ utime_check_t checkme;
1209
+ const char* path = ".";
1210
+ double atime;
1211
+ double mtime;
1212
+ uv_file file;
1213
+ uv_fs_t req;
1214
+ int r;
1215
+
1216
+ loop = uv_default_loop();
1217
+
1218
+ atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
1219
+
1220
+ r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL);
1221
+ ASSERT(r != -1);
1222
+ ASSERT(req.result != -1);
1223
+ file = req.result; /* FIXME probably not how it's supposed to be used */
1224
+ uv_fs_req_cleanup(&req);
1225
+
1226
+ r = uv_fs_futime(loop, &req, file, atime, mtime, NULL);
1227
+ ASSERT(r == 0);
1228
+ ASSERT(req.result == 0);
1229
+ uv_fs_req_cleanup(&req);
1230
+
1231
+ r = uv_fs_stat(loop, &req, path, NULL);
1232
+ ASSERT(r == 0);
1233
+ ASSERT(req.result == 0);
1234
+ check_utime(path, atime, mtime);
1235
+ uv_fs_req_cleanup(&req);
1236
+
1237
+ atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
1238
+
1239
+ checkme.atime = atime;
1240
+ checkme.mtime = mtime;
1241
+ checkme.path = path;
1242
+
1243
+ /* async futime */
1244
+ futime_req.data = &checkme;
1245
+ r = uv_fs_futime(loop, &futime_req, file, atime, mtime, futime_cb);
1246
+ ASSERT(r == 0);
1247
+ uv_run(loop);
1248
+ ASSERT(futime_cb_count == 1);
713
1249
 
714
1250
  return 0;
715
1251
  }