Alien-uv
view release on metacpan or search on metacpan
libuv/src/win/fs.c view on Meta::CPAN
SET_REQ_RESULT(req, dirent_idx);
return;
error:
SET_REQ_WIN32_ERROR(req, GetLastError());
for (i = 0; i < dirent_idx; ++i) {
uv__free((char*) dirents[i].name);
dirents[i].name = NULL;
}
}
void fs__closedir(uv_fs_t* req) {
uv_dir_t* dir;
dir = req->ptr;
FindClose(dir->dir_handle);
uv__free(req->ptr);
SET_REQ_RESULT(req, 0);
}
INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf,
int do_lstat) {
FILE_ALL_INFORMATION file_info;
FILE_FS_VOLUME_INFORMATION volume_info;
NTSTATUS nt_status;
IO_STATUS_BLOCK io_status;
nt_status = pNtQueryInformationFile(handle,
&io_status,
&file_info,
sizeof file_info,
FileAllInformation);
/* Buffer overflow (a warning status code) is expected here. */
if (NT_ERROR(nt_status)) {
SetLastError(pRtlNtStatusToDosError(nt_status));
return -1;
}
nt_status = pNtQueryVolumeInformationFile(handle,
&io_status,
&volume_info,
sizeof volume_info,
FileFsVolumeInformation);
/* Buffer overflow (a warning status code) is expected here. */
if (io_status.Status == STATUS_NOT_IMPLEMENTED) {
statbuf->st_dev = 0;
} else if (NT_ERROR(nt_status)) {
SetLastError(pRtlNtStatusToDosError(nt_status));
return -1;
} else {
statbuf->st_dev = volume_info.VolumeSerialNumber;
}
/* Todo: st_mode should probably always be 0666 for everyone. We might also
* want to report 0777 if the file is a .exe or a directory.
*
* Currently it's based on whether the 'readonly' attribute is set, which
* makes little sense because the semantics are so different: the 'read-only'
* flag is just a way for a user to protect against accidental deletion, and
* serves no security purpose. Windows uses ACLs for that.
*
* Also people now use uv_fs_chmod() to take away the writable bit for good
* reasons. Windows however just makes the file read-only, which makes it
* impossible to delete the file afterwards, since read-only files can't be
* deleted.
*
* IOW it's all just a clusterfuck and we should think of something that
* makes slightly more sense.
*
* And uv_fs_chmod should probably just fail on windows or be a total no-op.
* There's nothing sensible it can do anyway.
*/
statbuf->st_mode = 0;
/*
* On Windows, FILE_ATTRIBUTE_REPARSE_POINT is a general purpose mechanism
* by which filesystem drivers can intercept and alter file system requests.
*
* The only reparse points we care about are symlinks and mount points, both
* of which are treated as POSIX symlinks. Further, we only care when
* invoked via lstat, which seeks information about the link instead of its
* target. Otherwise, reparse points must be treated as regular files.
*/
if (do_lstat &&
(file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
/*
* If reading the link fails, the reparse point is not a symlink and needs
* to be treated as a regular file. The higher level lstat function will
* detect this failure and retry without do_lstat if appropriate.
*/
if (fs__readlink_handle(handle, NULL, &statbuf->st_size) != 0)
return -1;
statbuf->st_mode |= S_IFLNK;
}
if (statbuf->st_mode == 0) {
if (file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
statbuf->st_mode |= _S_IFDIR;
statbuf->st_size = 0;
} else {
statbuf->st_mode |= _S_IFREG;
statbuf->st_size = file_info.StandardInformation.EndOfFile.QuadPart;
}
}
if (file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_READONLY)
statbuf->st_mode |= _S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6);
else
statbuf->st_mode |= (_S_IREAD | _S_IWRITE) | ((_S_IREAD | _S_IWRITE) >> 3) |
((_S_IREAD | _S_IWRITE) >> 6);
FILETIME_TO_TIMESPEC(statbuf->st_atim, file_info.BasicInformation.LastAccessTime);
FILETIME_TO_TIMESPEC(statbuf->st_ctim, file_info.BasicInformation.ChangeTime);
FILETIME_TO_TIMESPEC(statbuf->st_mtim, file_info.BasicInformation.LastWriteTime);
FILETIME_TO_TIMESPEC(statbuf->st_birthtim, file_info.BasicInformation.CreationTime);
statbuf->st_ino = file_info.InternalInformation.IndexNumber.QuadPart;
/* st_blocks contains the on-disk allocation size in 512-byte units. */
( run in 0.469 second using v1.01-cache-2.11-cpan-13bb782fe5a )