Copyright | (c) Dong Han 2017~2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provide IO operations related to filesystem, operations are implemented using unsafe FFIs, which should be prefered when the operations' estimated time is short(<1ms), which is much common on modern SSDs.
Synopsis
- data UVFile
- data UVFileReader
- newUVFileReader :: UVFile -> Int64 -> IO UVFileReader
- peekUVFileReader :: UVFileReader -> Int64 -> IO Int64
- data UVFileWriter
- newUVFileWriter :: UVFile -> Int64 -> IO UVFileWriter
- peekUVFileWriter :: UVFileWriter -> Int64 -> IO Int64
- initUVFile :: HasCallStack => CBytes -> UVFileFlag -> UVFileMode -> Resource UVFile
- data UVFileMode where
- pattern DEFAULT_MODE :: UVFileMode
- pattern S_IRWXU :: UVFileMode
- pattern S_IRUSR :: UVFileMode
- pattern S_IWUSR :: UVFileMode
- pattern S_IXUSR :: UVFileMode
- pattern S_IRWXG :: UVFileMode
- pattern S_IRGRP :: UVFileMode
- pattern S_IWGRP :: UVFileMode
- pattern S_IXGRP :: UVFileMode
- pattern S_IRWXO :: UVFileMode
- pattern S_IROTH :: UVFileMode
- data UVFileFlag where
- pattern O_APPEND :: UVFileFlag
- pattern O_CREAT :: UVFileFlag
- pattern O_DIRECT :: UVFileFlag
- pattern O_DSYNC :: UVFileFlag
- pattern O_EXCL :: UVFileFlag
- pattern O_EXLOCK :: UVFileFlag
- pattern O_NOATIME :: UVFileFlag
- pattern O_NOFOLLOW :: UVFileFlag
- pattern O_RDONLY :: UVFileFlag
- pattern O_RDWR :: UVFileFlag
- pattern O_SYMLINK :: UVFileFlag
- pattern O_SYNC :: UVFileFlag
- pattern O_TRUNC :: UVFileFlag
- pattern O_WRONLY :: UVFileFlag
- pattern O_RANDOM :: UVFileFlag
- pattern O_SHORT_LIVED :: UVFileFlag
- pattern O_SEQUENTIAL :: UVFileFlag
- pattern O_TEMPORARY :: UVFileFlag
- mkdir :: HasCallStack => CBytes -> UVFileMode -> IO ()
- unlink :: HasCallStack => CBytes -> IO ()
- mkdtemp :: HasCallStack => CBytes -> IO CBytes
- rmdir :: HasCallStack => CBytes -> IO ()
- data DirEntType
- scandir :: HasCallStack => CBytes -> IO [(CBytes, DirEntType)]
- data UVStat = UVStat {}
- data UVTimeSpec = UVTimeSpec {
- uvtSecond :: !CLong
- uvtNanoSecond :: !CLong
- stat :: HasCallStack => CBytes -> IO UVStat
- lstat :: HasCallStack => CBytes -> IO UVStat
- fstat :: HasCallStack => UVFile -> IO UVStat
- rename :: HasCallStack => CBytes -> CBytes -> IO ()
- fsync :: HasCallStack => UVFile -> IO ()
- fdatasync :: HasCallStack => UVFile -> IO ()
- ftruncate :: HasCallStack => UVFile -> Int64 -> IO ()
- data UVCopyFileFlag where
- pattern COPYFILE_DEFAULT :: UVCopyFileFlag
- pattern COPYFILE_EXCL :: UVCopyFileFlag
- pattern COPYFILE_FICLONE :: UVCopyFileFlag
- copyfile :: HasCallStack => CBytes -> CBytes -> UVCopyFileFlag -> IO ()
- data UVAccessMode where
- pattern F_OK :: UVAccessMode
- pattern R_OK :: UVAccessMode
- pattern W_OK :: UVAccessMode
- pattern X_OK :: UVAccessMode
- data AccessResult
- access :: HasCallStack => CBytes -> UVAccessMode -> IO AccessResult
- chmod :: HasCallStack => CBytes -> UVFileMode -> IO ()
- fchmod :: HasCallStack => UVFile -> UVFileMode -> IO ()
- utime :: HasCallStack => CBytes -> Double -> Double -> IO ()
- futime :: HasCallStack => UVFile -> Double -> Double -> IO ()
- data UVSymlinkFlag where
- pattern SYMLINK_DEFAULT :: UVSymlinkFlag
- pattern SYMLINK_DIR :: UVSymlinkFlag
- pattern SYMLINK_JUNCTION :: UVSymlinkFlag
- link :: HasCallStack => CBytes -> CBytes -> IO ()
- symlink :: HasCallStack => CBytes -> CBytes -> UVSymlinkFlag -> IO ()
- readlink :: HasCallStack => CBytes -> IO CBytes
- realpath :: HasCallStack => CBytes -> IO CBytes
regular file devices
UVFile
wrap a uv_file_t
and a referencing counter.
libuv implements read and write method with both implict and explict offset capable.
(negative offset result in read/write
system call otherwise pread/pwrite
), we provide
implict offset interface with UVFile
, which is NOT thread safe.
An offset bundled UVFileReader
, UVFileWriter
is also provided, which can be used
concurrently. The offset is protected with MVar
and increasing automatically.
data UVFileReader Source #
Instances
Input UVFileReader Source # | |
Defined in Std.IO.FileSystem |
:: UVFile | the file we're reading |
-> Int64 | initial reading offset |
-> IO UVFileReader |
Create a reader from an UVFile
.
Note this will not increase UVFile'
s referencing counter.
:: UVFileReader | |
-> Int64 | the new offset |
-> IO Int64 | the old offset |
Change reader's offset.
data UVFileWriter Source #
Instances
Output UVFileWriter Source # | |
Defined in Std.IO.FileSystem writeOutput :: UVFileWriter -> Ptr Word8 -> Int -> IO () Source # |
:: UVFile | the file we're writing |
-> Int64 | initial writing offset |
-> IO UVFileWriter |
Create a writer from an UVFile
.
Note this will not increase UVFile'
s referencing counter.
:: UVFileWriter | |
-> Int64 | the new offset |
-> IO Int64 | the old offset |
Change writer's offset.
:: HasCallStack | |
=> CBytes | |
-> UVFileFlag | |
-> UVFileMode | Sets the file mode (permission and sticky bits),
but only if the file was created, see |
-> Resource UVFile |
init a file Resource
, which open a file when used.
Resource closing will wait for the referencing counter goes down to zero (no reading or writing is in process), which can be a problem if you are using multiple readers or writers in multiple threads. In that case you have to stop all reading or writing thread if you don't want to block the resource thread.
Note, on some versions of OSX, repeatly open and close same file Resource
may
result in shared memory object error, use O_CREAT
to avoid that.
opening constant
data UVFileMode where Source #
pattern DEFAULT_MODE :: UVFileMode | Default mode for open, 0o666(readable and writable). |
pattern S_IRWXU :: UVFileMode | 00700 user (file owner) has read, write and execute permission |
pattern S_IRUSR :: UVFileMode | 00400 user has read permission |
pattern S_IWUSR :: UVFileMode | 00200 user has write permission |
pattern S_IXUSR :: UVFileMode | 00100 user has execute permission |
pattern S_IRWXG :: UVFileMode | 00070 group has read, write and execute permission |
pattern S_IRGRP :: UVFileMode | 00040 group has read permission |
pattern S_IWGRP :: UVFileMode | 00020 group has write permission |
pattern S_IXGRP :: UVFileMode | 00010 group has execute permission |
pattern S_IRWXO :: UVFileMode | 00007 others have read, write and execute permission |
pattern S_IROTH :: UVFileMode | 00004 others have read permission |
Instances
data UVFileFlag where Source #
pattern O_APPEND :: UVFileFlag | The file is opened in append mode. Before each write, the file offset is positioned at the end of the file. |
pattern O_CREAT :: UVFileFlag | The file is created if it does not already exist. |
pattern O_DIRECT :: UVFileFlag | File IO is done directly to and from user-space buffers, which must be aligned. Buffer size and address should be a multiple of the physical sector size of the block device, (DO NOT USE WITH stdio's |
pattern O_DSYNC :: UVFileFlag | The file is opened for synchronous IO. Write operations will complete once all data and a minimum of metadata are flushed to disk. Note |
pattern O_EXCL :: UVFileFlag | If the Note In general, the behavior of |
pattern O_EXLOCK :: UVFileFlag | Atomically obtain an exclusive lock. Note UV_FS_O_EXLOCK is only supported on macOS and Windows. (libuv: Changed in version 1.17.0: support is added for Windows.) |
pattern O_NOATIME :: UVFileFlag | Do not update the file access time when the file is read. Note |
pattern O_NOFOLLOW :: UVFileFlag | If the path is a symbolic link, fail the open. Note |
pattern O_RDONLY :: UVFileFlag | Open the file for read-only access. |
pattern O_RDWR :: UVFileFlag | Open the file for read-write access. |
pattern O_SYMLINK :: UVFileFlag | Open the symbolic link itself rather than the resource it points to. |
pattern O_SYNC :: UVFileFlag | The file is opened for synchronous IO. Write operations will complete once all data and all metadata are flushed to disk. Note |
pattern O_TRUNC :: UVFileFlag | If the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. |
pattern O_WRONLY :: UVFileFlag | Open the file for write-only access. |
pattern O_RANDOM :: UVFileFlag | Access is intended to be random. The system can use this as a hint to optimize file caching. Note |
pattern O_SHORT_LIVED :: UVFileFlag | The file is temporary and should not be flushed to disk if possible. Note |
pattern O_SEQUENTIAL :: UVFileFlag | Access is intended to be sequential from beginning to end. The system can use this as a hint to optimize file caching. Note |
pattern O_TEMPORARY :: UVFileFlag | The file is temporary and should not be flushed to disk if possible. Note |
Instances
filesystem operations
mkdir :: HasCallStack => CBytes -> UVFileMode -> IO () Source #
Equivalent to mkdir(2).
Note mode is currently not implemented on Windows.
mkdtemp :: HasCallStack => CBytes -> IO CBytes Source #
Equivalent to http://linux.die.net/man/3/mkdtemp
Creates a temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable, writable, and searchable only by the creating user ID. The user of mkdtemp() is responsible for deleting the temporary directory and its contents when done with it.
Note: the argument is the prefix of the temporary directory, so no need to add XXXXXX ending.
data DirEntType Source #
Instances
scandir :: HasCallStack => CBytes -> IO [(CBytes, DirEntType)] Source #
Equivalent to scandir(3).
Note Unlike scandir(3), this function does not return the “.” and “..” entries.
Note On Linux, getting the type of an entry is only supported by some file systems (btrfs, ext2, ext3 and ext4 at the time of this writing), check the getdents(2) man page.
UVStat | |
|
Instances
data UVTimeSpec Source #
UVTimeSpec | |
|
Instances
rename :: HasCallStack => CBytes -> CBytes -> IO () Source #
Equivalent to rename(2).
Note On Windows if this function fails with UV_EBUSY, UV_EPERM or UV_EACCES, it will retry to rename the file up to four times with 250ms wait between attempts before giving up. If both path and new_path are existing directories this function will work only if target directory is empty.
fdatasync :: HasCallStack => UVFile -> IO () Source #
Equivalent to fdatasync(2).
ftruncate :: HasCallStack => UVFile -> Int64 -> IO () Source #
Equivalent to ftruncate(2).
data UVCopyFileFlag where Source #
Flags control copying.
COPYFILE_EXCL
: If present, uv_fs_copyfile() will fail with UV_EEXIST if the destination path already exists. The default behavior is to overwrite the destination if it exists.COPYFILE_FICLONE
: If present, uv_fs_copyfile() will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
pattern COPYFILE_DEFAULT :: UVCopyFileFlag | |
pattern COPYFILE_EXCL :: UVCopyFileFlag | |
pattern COPYFILE_FICLONE :: UVCopyFileFlag |
Instances
copyfile :: HasCallStack => CBytes -> CBytes -> UVCopyFileFlag -> IO () Source #
Copies a file from path to new_path.
Warning: If the destination path is created, but an error occurs while copying the data, then the destination path is removed. There is a brief window of time between closing and removing the file where another process could access the file.
data UVAccessMode where Source #
pattern F_OK :: UVAccessMode | |
pattern R_OK :: UVAccessMode | |
pattern W_OK :: UVAccessMode | |
pattern X_OK :: UVAccessMode |
Instances
data AccessResult Source #
Instances
Eq AccessResult Source # | |
Defined in Std.IO.UV.FFI (==) :: AccessResult -> AccessResult -> Bool # (/=) :: AccessResult -> AccessResult -> Bool # | |
Ord AccessResult Source # | |
Defined in Std.IO.UV.FFI compare :: AccessResult -> AccessResult -> Ordering # (<) :: AccessResult -> AccessResult -> Bool # (<=) :: AccessResult -> AccessResult -> Bool # (>) :: AccessResult -> AccessResult -> Bool # (>=) :: AccessResult -> AccessResult -> Bool # max :: AccessResult -> AccessResult -> AccessResult # min :: AccessResult -> AccessResult -> AccessResult # | |
Show AccessResult Source # | |
Defined in Std.IO.UV.FFI showsPrec :: Int -> AccessResult -> ShowS # show :: AccessResult -> String # showList :: [AccessResult] -> ShowS # |
access :: HasCallStack => CBytes -> UVAccessMode -> IO AccessResult Source #
Equivalent to access(2) on Unix. Windows uses GetFileAttributesW().
chmod :: HasCallStack => CBytes -> UVFileMode -> IO () Source #
Equivalent to chmod(2).
fchmod :: HasCallStack => UVFile -> UVFileMode -> IO () Source #
Equivalent to fchmod(2).
:: HasCallStack | |
=> CBytes | |
-> Double | atime, i.e. access time |
-> Double | mtime, i.e. modify time |
-> IO () |
Equivalent to utime(2).
libuv choose Double
type due to cross platform concerns, we only provide micro-second precision:
- second = v
- nanosecond = (v * 1000000) % 1000000 * 1000;
second and nanosecond are fields in UVTimeSpec
respectively.
Note libuv prior to v1.23.1 have issues which may result in nanosecond not set, futime
doesn't have
that issue.
data UVSymlinkFlag where Source #
pattern SYMLINK_DEFAULT :: UVSymlinkFlag | |
pattern SYMLINK_DIR :: UVSymlinkFlag | |
pattern SYMLINK_JUNCTION :: UVSymlinkFlag |
Instances
symlink :: HasCallStack => CBytes -> CBytes -> UVSymlinkFlag -> IO () Source #
Equivalent to symlink(2).
| Note On Windows the flags parameter can be specified to control how the symlink will be created.
SYMLINK_DIR
: indicates that path points to a directory.SYMLINK_JUNCTION
: request that the symlink is created using junction points.
On other platforms these flags are ignored.
readlink :: HasCallStack => CBytes -> IO CBytes Source #
Equivalent to readlink(2).
realpath :: HasCallStack => CBytes -> IO CBytes Source #
Equivalent to realpath(3) on Unix. Windows uses GetFinalPathNameByHandle.
Warning This function has certain platform-specific caveats that were discovered when used in Node.
- macOS and other BSDs: this function will fail with UV_ELOOP if more than 32 symlinks are found while resolving the given path. This limit is hardcoded and cannot be sidestepped.
Windows: while this function works in the common case, there are a number of corner cases where it doesn’t:
- Paths in ramdisk volumes created by tools which sidestep the Volume Manager (such as ImDisk) cannot be resolved.
- Inconsistent casing when using drive letters.
- Resolved path bypasses subst’d drives.
While this function can still be used, it’s not recommended if scenarios such as the above need to be supported. The background story and some more details on these issues can be checked here.
Note This function is not implemented on Windows XP and Windows Server 2003. On these systems, UV_ENOSYS is returned.