Alien-uv

 view release on metacpan or  search on metacpan

libuv/test/test-fs-copyfile.c  view on Meta::CPAN

  ASSERT(r == 0);
  handle_result(&req);

  /* Copies file synchronously. Overwrites existing file. */
  r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
  ASSERT(r == 0);
  handle_result(&req);

  /* Fails to overwrites existing file. */
  r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_EXCL, NULL);
  ASSERT(r == UV_EEXIST);
  uv_fs_req_cleanup(&req);

  /* Truncates when an existing destination is larger than the source file. */
  touch_file(src, 1);
  r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
  ASSERT(r == 0);
  handle_result(&req);

  /* Copies a larger file. */
  unlink(dst);
  touch_file(src, 4096 * 2);
  r = uv_fs_copyfile(NULL, &req, src, dst, 0, NULL);
  ASSERT(r == 0);
  handle_result(&req);
  unlink(src);

  /* Copies file asynchronously */
  unlink(dst);
  r = uv_fs_copyfile(loop, &req, fixture, dst, 0, handle_result);
  ASSERT(r == 0);
  ASSERT(result_check_count == 5);
  uv_run(loop, UV_RUN_DEFAULT);
  ASSERT(result_check_count == 6);

  /* If the flags are invalid, the loop should not be kept open */
  unlink(dst);
  r = uv_fs_copyfile(loop, &req, fixture, dst, -1, fail_cb);
  ASSERT(r == UV_EINVAL);
  uv_run(loop, UV_RUN_DEFAULT);

  /* Copies file using UV_FS_COPYFILE_FICLONE. */
  unlink(dst);
  r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE, NULL);
  ASSERT(r == 0);
  handle_result(&req);

  /* Copies file using UV_FS_COPYFILE_FICLONE_FORCE. */
  unlink(dst);
  r = uv_fs_copyfile(NULL, &req, fixture, dst, UV_FS_COPYFILE_FICLONE_FORCE,
                     NULL);
  ASSERT(r == 0 || r == UV_ENOSYS || r == UV_ENOTSUP);

  if (r == 0)
    handle_result(&req);

#ifndef _WIN32
  /* Copying respects permissions/mode. */
  unlink(dst);
  touch_file(dst, 0);
  chmod(dst, S_IRUSR|S_IRGRP|S_IROTH); /* Sets file mode to 444 (read-only). */
  r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
  ASSERT(req.result == UV_EACCES);
  ASSERT(r == UV_EACCES);
  uv_fs_req_cleanup(&req);
#endif

  unlink(dst); /* Cleanup */
  return 0;
}



( run in 0.379 second using v1.01-cache-2.11-cpan-f0fbb3f571b )