~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to deps/uv/src/win/fs-event.c

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <errno.h>
25
25
#include <stdio.h>
26
26
#include <string.h>
 
27
 
27
28
#include "uv.h"
28
29
#include "internal.h"
 
30
#include "handle-inl.h"
 
31
#include "req-inl.h"
29
32
 
30
33
 
31
34
const unsigned int uv_directory_watcher_buffer_size = 4096;
33
36
 
34
37
static void uv_fs_event_init_handle(uv_loop_t* loop, uv_fs_event_t* handle,
35
38
    const char* filename, uv_fs_event_cb cb) {
36
 
  handle->type = UV_FS_EVENT;
37
 
  handle->loop = loop;
38
 
  handle->flags = 0;
 
39
  uv__handle_init(loop, (uv_handle_t*) handle, UV_FS_EVENT);
39
40
  handle->cb = cb;
40
41
  handle->dir_handle = INVALID_HANDLE_VALUE;
41
42
  handle->buffer = NULL;
53
54
    uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
54
55
  }
55
56
 
56
 
  loop->counters.handle_init++;
57
 
  loop->counters.fs_event_init++;
58
 
 
59
 
  uv_ref(loop);
 
57
  uv__handle_start(handle);
60
58
}
61
59
 
62
60
 
90
88
}
91
89
 
92
90
 
93
 
static int uv_split_path(const wchar_t* filename, wchar_t** dir,
94
 
    wchar_t** file) {
 
91
static int uv_split_path(const WCHAR* filename, WCHAR** dir,
 
92
    WCHAR** file) {
95
93
  int len = wcslen(filename);
96
94
  int i = len;
97
95
  while (i > 0 && filename[--i] != '\\' && filename[i] != '/');
98
96
 
99
97
  if (i == 0) {
100
98
    if (dir) {
101
 
      *dir = (wchar_t*)malloc((MAX_PATH + 1) * sizeof(wchar_t));
 
99
      *dir = (WCHAR*)malloc((MAX_PATH + 1) * sizeof(WCHAR));
102
100
      if (!*dir) {
103
101
        uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
104
102
      }
109
107
        return -1;
110
108
      }
111
109
    }
112
 
    
 
110
 
113
111
    *file = wcsdup(filename);
114
112
  } else {
115
113
    if (dir) {
116
 
      *dir = (wchar_t*)malloc((i + 1) * sizeof(wchar_t));
 
114
      *dir = (WCHAR*)malloc((i + 1) * sizeof(WCHAR));
117
115
      if (!*dir) {
118
116
        uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
119
117
      }
121
119
      (*dir)[i] = L'\0';
122
120
    }
123
121
 
124
 
    *file = (wchar_t*)malloc((len - i) * sizeof(wchar_t));
 
122
    *file = (WCHAR*)malloc((len - i) * sizeof(WCHAR));
125
123
    if (!*file) {
126
124
      uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
127
125
    }
137
135
    const char* filename, uv_fs_event_cb cb, int flags) {
138
136
  int name_size, is_path_dir;
139
137
  DWORD attr, last_error;
140
 
  wchar_t* dir = NULL, *dir_to_watch, *filenamew = NULL;
141
 
  wchar_t short_path[MAX_PATH];
142
 
 
143
 
  /* We don't support any flags yet. */
144
 
  assert(!flags);
 
138
  WCHAR* dir = NULL, *dir_to_watch, *filenamew = NULL;
 
139
  WCHAR short_path[MAX_PATH];
145
140
 
146
141
  uv_fs_event_init_handle(loop, handle, filename, cb);
147
142
 
148
143
  /* Convert name to UTF16. */
149
 
  name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(wchar_t);
150
 
  filenamew = (wchar_t*)malloc(name_size);
 
144
  name_size = uv_utf8_to_utf16(filename, NULL, 0) * sizeof(WCHAR);
 
145
  filenamew = (WCHAR*)malloc(name_size);
151
146
  if (!filenamew) {
152
147
    uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
153
148
  }
154
149
 
155
 
  if (!uv_utf8_to_utf16(filename, filenamew, 
156
 
      name_size / sizeof(wchar_t))) {
 
150
  if (!uv_utf8_to_utf16(filename, filenamew,
 
151
      name_size / sizeof(WCHAR))) {
157
152
    uv__set_sys_error(loop, GetLastError());
158
153
    return -1;
159
154
  }
172
167
    handle->dirw = filenamew;
173
168
    dir_to_watch = filenamew;
174
169
  } else {
175
 
    /* 
 
170
    /*
176
171
     * filename is a file.  So we split filename into dir & file parts, and
177
172
     * watch the dir directory.
178
173
     */
179
 
    
 
174
 
180
175
    /* Convert to short path. */
181
 
    if (!GetShortPathNameW(filenamew, short_path, COUNTOF(short_path))) {
 
176
    if (!GetShortPathNameW(filenamew, short_path, ARRAY_SIZE(short_path))) {
182
177
      last_error = GetLastError();
183
178
      goto error;
184
179
    }
226
221
    goto error;
227
222
  }
228
223
 
229
 
  handle->buffer = (char*)_aligned_malloc(uv_directory_watcher_buffer_size, 
 
224
  handle->buffer = (char*)_aligned_malloc(uv_directory_watcher_buffer_size,
230
225
    sizeof(DWORD));
231
226
  if (!handle->buffer) {
232
227
    uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
294
289
  FILE_NOTIFY_INFORMATION* file_info;
295
290
  int sizew, size, result;
296
291
  char* filename = NULL;
297
 
  wchar_t* filenamew, *long_filenamew = NULL;
 
292
  WCHAR* filenamew, *long_filenamew = NULL;
298
293
  DWORD offset = 0;
299
294
 
300
295
  assert(req->type == UV_FS_EVENT_REQ);
303
298
 
304
299
  /* If we're closing, don't report any callbacks, and just push the handle */
305
300
  /* onto the endgame queue. */
306
 
  if (handle->flags & UV_HANDLE_CLOSING) {
 
301
  if (handle->flags & UV__HANDLE_CLOSING) {
307
302
    uv_want_endgame(loop, (uv_handle_t*) handle);
308
303
    return;
309
304
  };
317
312
        assert(!filename);
318
313
        assert(!long_filenamew);
319
314
 
320
 
        /* 
 
315
        /*
321
316
         * Fire the event only if we were asked to watch a directory,
322
317
         * or if the filename filter matches.
323
318
         */
324
319
        if (handle->dirw ||
325
320
          _wcsnicmp(handle->filew, file_info->FileName,
326
 
            file_info->FileNameLength / sizeof(wchar_t)) == 0 ||
 
321
            file_info->FileNameLength / sizeof(WCHAR)) == 0 ||
327
322
          _wcsnicmp(handle->short_filew, file_info->FileName,
328
 
            file_info->FileNameLength / sizeof(wchar_t)) == 0) {
 
323
            file_info->FileNameLength / sizeof(WCHAR)) == 0) {
329
324
 
330
325
          if (handle->dirw) {
331
 
            /* 
332
 
             * We attempt to convert the file name to its long form for 
 
326
            /*
 
327
             * We attempt to convert the file name to its long form for
333
328
             * events that still point to valid files on disk.
334
329
             * For removed and renamed events, we do not provide the file name.
335
330
             */
337
332
              file_info->Action != FILE_ACTION_RENAMED_OLD_NAME) {
338
333
              /* Construct a full path to the file. */
339
334
              size = wcslen(handle->dirw) +
340
 
                file_info->FileNameLength / sizeof(wchar_t) + 2;
 
335
                file_info->FileNameLength / sizeof(WCHAR) + 2;
341
336
 
342
 
              filenamew = (wchar_t*)malloc(size * sizeof(wchar_t));
 
337
              filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
343
338
              if (!filenamew) {
344
339
                uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
345
340
              }
353
348
              size = GetLongPathNameW(filenamew, NULL, 0);
354
349
 
355
350
              if (size) {
356
 
                long_filenamew = (wchar_t*)malloc(size * sizeof(wchar_t));
 
351
                long_filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
357
352
                if (!long_filenamew) {
358
353
                  uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
359
354
                }
382
377
                }
383
378
              }
384
379
 
385
 
              /* 
 
380
              /*
386
381
               * If we couldn't get the long name - just use the name
387
382
               * provided by ReadDirectoryChangesW.
388
383
               */
389
384
              if (!long_filenamew) {
390
385
                filenamew = file_info->FileName;
391
 
                sizew = file_info->FileNameLength / sizeof(wchar_t);
 
386
                sizew = file_info->FileNameLength / sizeof(WCHAR);
392
387
              }
393
388
            } else {
394
389
              /* Removed or renamed callbacks don't provide filename. */
445
440
        }
446
441
 
447
442
        offset = file_info->NextEntryOffset;
448
 
      } while (offset && !(handle->flags & UV_HANDLE_CLOSING));
 
443
      } while (offset && !(handle->flags & UV__HANDLE_CLOSING));
449
444
    } else {
450
445
      handle->cb(handle, NULL, UV_CHANGE, 0);
451
446
    }
454
449
    handle->cb(handle, NULL, 0, -1);
455
450
  }
456
451
 
457
 
  if (!(handle->flags & UV_HANDLE_CLOSING)) {
 
452
  if (!(handle->flags & UV__HANDLE_CLOSING)) {
458
453
    uv_fs_event_queue_readdirchanges(loop, handle);
459
454
  } else {
460
455
    uv_want_endgame(loop, (uv_handle_t*)handle);
471
466
  if (!handle->req_pending) {
472
467
    uv_want_endgame(loop, (uv_handle_t*)handle);
473
468
  }
 
469
 
 
470
  uv__handle_closing(handle);
474
471
}
475
472
 
476
473
 
477
474
void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle) {
478
 
  if (handle->flags & UV_HANDLE_CLOSING &&
 
475
  if (handle->flags & UV__HANDLE_CLOSING &&
479
476
      !handle->req_pending) {
480
477
    assert(!(handle->flags & UV_HANDLE_CLOSED));
481
 
    handle->flags |= UV_HANDLE_CLOSED;
482
478
 
483
479
    if (handle->buffer) {
484
480
      _aligned_free(handle->buffer);
505
501
      handle->dirw = NULL;
506
502
    }
507
503
 
508
 
    if (handle->close_cb) {
509
 
      handle->close_cb((uv_handle_t*)handle);
510
 
    }
511
 
 
512
 
    uv_unref(loop);
 
504
    uv__handle_close(handle);
513
505
  }
514
506
}