ae.sys.file

File stuff

Members

Aliases

FSChar
alias FSChar = WCHAR

The OS's "native" filesystem character type (private in Phobos).

FSChar
alias FSChar = char
Undocumented in source.
NamedPipe
alias NamedPipe = RefCounted!NamedPipeImpl
Undocumented in source.
atomicCopy
alias atomicCopy = atomic!copy2

Copy a file, or replace an existing file's contents with another file's, atomically.

atomicSymlink
alias atomicSymlink = atomic!(symlink!(string, string), "link")
Undocumented in source.
atomicWrite
alias atomicWrite = atomic!_writeProxy

Create a file, or replace an existing file's contents atomically. Note: Consider using atomic!syncWrite or atomic!syncUpdate instead.

collectFileExistsError
alias collectFileExistsError = collectOSError!(errno => errno == core.stdc.errno.EEXIST, (code))

Collect a "file already exists" error.

collectNotFoundError
alias collectNotFoundError = collectOSError!(errno => errno == core.stdc.errno.ENOENT, (code))

Collect a "file not found" error.

deleteHardLink
alias deleteHardLink = remove
Undocumented in source.
dirLink
alias dirLink = std.file.symlink
Undocumented in source.
getSize2
deprecated alias getSize2 = std.file.getSize
Undocumented in source.
obtainUsing
deprecated alias obtainUsing = cached
Undocumented in source.
safeUpdate
deprecated alias safeUpdate = atomic
Undocumented in source.
safeWrite
deprecated alias safeWrite = atomicWrite
Undocumented in source.
toFile
alias toFile = std.stdio.toFile

Argument-reversed version of std.file.write, usable at the end of an UFCS chain.

wcscmp
deprecated alias wcscmp = core.stdc.wchar_.wcscmp
Undocumented in source.
wcslen
deprecated alias wcslen = core.stdc.wchar_.wcslen
Undocumented in source.

Functions

_writeProxy
void _writeProxy(string target, const(void)[] data)
Undocumented in source. Be warned that the author may not have intended to support it.
acquirePrivilege
void acquirePrivilege(S name)

Attempt to acquire the specified privilege.

anyNewerThan
bool anyNewerThan(string[] sources, string target)

Returns true if the target file doesn't exist, or any of the sources are newer than the target.

atomic
auto atomic(staticMap!(Unqual, ParameterTypeTuple!impl) args)
atomicDg
auto atomicDg(Impl impl, Args args)

Wrap an operation which creates a file or directory, so that it is created safely and, for files, atomically (by performing the underlying operation to a temporary location, then renaming the completed file/directory to the actual target location). targetName specifies the name of the parameter containing the target file/directory.

atomicExchange
void atomicExchange(string a, string b)

Atomically exchange the given files.

atomicSymlink
void atomicSymlink(char[] original, char[] link)

Like symlink, but replaces it atomically if it already exists.

cached
auto cached(ParameterTypeTuple!impl args)
cachedDg
auto cachedDg(Impl impl, Args args)

Wrap an operation so that it is skipped entirely if the target already exists. Implies atomic.

collectOSError
bool collectOSError(void delegate() operation)

Catch common Phobos exception types corresponding to file operations.

copyRecurse
void copyRecurse(DirEntry src, string dst)

Copy a directory recursively.

copyRecurse
void copyRecurse(string src, string dst)
Undocumented in source. Be warned that the author may not have intended to support it.
createLinkTargets
void createLinkTargets(string path, bool isFile)

Ensure that realPath(path) exists, creating a file or directory (according to isFile) as necessary, as well as any missing directory components or symlink targets (recursively if necessary).

deleteHardLink
void deleteHardLink(string fn)

Deletes a file, which might be a read-only hard link (thus, deletes the read-only file/link without affecting other links to it).

dirLink
void dirLink(char[] original, char[] link)

Link a directory. Uses symlinks on POSIX, and directory junctions on Windows.

ensureDirExists
void ensureDirExists(string path)

Make sure that the given directory exists (and create parent directories as necessary).

ensureFileExists
void ensureFileExists(string fn)

Combines ensurePathExists and touch.

ensurePathExists
void ensurePathExists(string fn)

Make sure that the path to the given file name exists (and create directories as necessary).

enumerateHardLinks
string[] enumerateHardLinks(string fn)

Enumerate all hard links to the specified file.

fastFileList
deprecated string[] fastFileList(string pattern)
deprecated string[] fastFileList(string pattern0, string[] patterns)

Shell-like expansion of ?, * and ** in path components

fastListDir
deprecated string[] fastListDir(string pathname, string pattern)
Undocumented in source. Be warned that the author may not have intended to support it.
fileDigest
auto fileDigest(string fn)

Calculate the digest of a file.

fileDigestCached
auto fileDigestCached(string fn)

Calculate the digest of a file, and memoize it.

fileList
DirEntry[] fileList(string pattern)
DirEntry[] fileList(string pattern0, string[] patterns)

Shell-like expansion of ?, * and ** in path components

forceDelete
void forceDelete(string fn, Flag!"recursive" recursive)

Forcibly remove a file or directory. If atomic is true, the entire directory is deleted "atomically" (it is first moved/renamed to another location). On Windows, this will move the file/directory out of the way, if it is in use and cannot be deleted (but can be renamed).

forceDelete
deprecated void forceDelete(string fn, bool recursive)
Undocumented in source. Be warned that the author may not have intended to support it.
getFileID
ulong getFileID(string fn)

Return a file's unique ID.

getGroup
int getGroup(string fn)

Get the ID of the group owning this file.

getMTime
deprecated SysTime getMTime(string name)
Undocumented in source. Be warned that the author may not have intended to support it.
getMounts
auto getMounts()

Returns an iterator of MountInfo structs.

getOwner
int getOwner(string fn)

Get the ID of the user owning this file.

getPathFilesystem
string getPathFilesystem(string path)

Get the name of the filesystem that the given path is mounted under. Returns null if none match.

getPathMountInfo
MountInfo getPathMountInfo(R mounts, string path)

Get MountInfo with longest mount point matching path. Returns MountInfo.init if none match.

getPathMountInfo
MountInfo getPathMountInfo(string path)
Undocumented in source. Be warned that the author may not have intended to support it.
hardLink
void hardLink(string src, string dst)

Create a hard link.

hardLink
void hardLink(string src, string dst)

Create a hard link.

hardLinkCount
uint hardLinkCount(string fn)

Obtain the hard link count for the given file.

isHidden
bool isHidden(string fn)

Return true if the given file would be hidden from directory listings. Returns true for files starting with '.', and, on Windows, hidden files.

isReadableFile
bool isReadableFile(string path)

Return true if we can open this path for reading as a file.

linkTarget
string linkTarget(string path)

Resolve the target of the symlink, returning a valid path (i.e. relative to path's base, not the symlink's directory).

linkXAttrs
auto linkXAttrs(string path)

Return XAttrs for the given path.

longPath
string longPath(string s)

Using UNC paths bypasses path length limitation when using Windows wide APIs.

move
void move(string src, string dst)

Try to rename; copy/delete if rename fails

newerThan
bool newerThan(string source, string target)

Returns true if the target file doesn't exist, or source is newer than the target.

openFile
File openFile(string fn, string mode)

Polyfill for Windows fopen implementations with support for UNC paths and the 'x' subspecifier.

parseMountInfo
MountInfo parseMountInfo(const(char)[] line)

Parse a line from /proc/self/mounts.

prependPath
string prependPath(string target, string path)

Two-argument buildPath with reversed arguments. Useful for UFCS chaining.

pushd
auto pushd(string dir)

Change the current directory to the given directory. Does nothing if dir is null. Return a scope guard which, upon destruction, restores the previous directory. Asserts that only one thread has changed the process's current directory at any time.

readAscii
ascii readAscii(string fileName)

Like std.file.readText for non-UTF8

readExactly
bool readExactly(File f, ubyte[] buf)

Read exactly buf.length bytes and return true. On EOF, return false.

readFile
ubyte[] readFile(File f)

Read a File (which might be a stream) into an array

readFileAsync
ubyte[] delegate() readFileAsync(File f)

Start a thread which reads data from f asynchronously. Call the returning delegate to obtain the read data, blocking until the read completes.

readPartial
void[] readPartial(File f, void[] buf)

Like File.rawRead, but returns as soon as any data is available.

realPath
string realPath(string path)

Wrapper around the C realpath function.

recreateEmptyDirectory
void recreateEmptyDirectory(string dir)

Create an empty directory, deleting all its contents if it already exists.

removeRecurse
void removeRecurse(string fn)

If fn is a directory, delete it recursively. Otherwise, delete the file or symlink fn.

safeReadln
string safeReadln(File f)

Avoid std.stdio.File.readln's memory corruption bug https://issues.dlang.org/show_bug.cgi?id=13856

setOwner
void setOwner(string fn, int uid, int gid)

Set the owner user and group of this file.

statTimeToStdTime
SysTime statTimeToStdTime(stat_t statbuf)

Reads a time field from a stat_t with full precision (private in Phobos).

symlink
void symlink(char[] original, char[] link)

Windows implementation of std.file.symlink.

syncUpdate
void syncUpdate(string fn, const(void)[] data)

Atomically save data to a file (if the file doesn't exist, or its contents differs). The update operation as a whole is not atomic, only the write is.

syncWrite
void syncWrite(string target, const(void)[] data)

Write data to a file, and ensure it gets written to disk before this function returns. Consider using as atomic!syncWrite. See also: syncUpdate

toFile
void toFile(const(void)[] data, char[] name)
Undocumented in source. Be warned that the author may not have intended to support it.
touch
void touch(char[] target)

If target exists, update its modification time; otherwise create it as an empty file.

truncate
void truncate(File f, ulong length)

Truncate the given file to the given size.

writeFileAsync
Thread writeFileAsync(File f, const(void)[] data)

Start a thread which writes data to f asynchronously.

writeTo
void writeTo(const(void)[] data, char[] target)

Same as toFile, but accepts void[] and does not conflict with the std.stdio function.

xAttrs
auto xAttrs(string path)

Return XAttrs for the given path, or the link destination if the path leads to as symbolic link.

xAttrs
auto xAttrs(File f)

Return XAttrs for the given open file.

Imports

No (from std.typecons)
public import std.typecons : No, Yes;
Undocumented in source.
Yes (from std.typecons)
public import std.typecons : No, Yes;
Undocumented in source.

Manifest constants

targetParameterNames
enum targetParameterNames;

Parameter names that atomic assumes indicate a destination file by default.

Structs

MountInfo
struct MountInfo

A parsed line from /proc/self/mounts.

NamedPipeImpl
struct NamedPipeImpl

Create a named pipe, and allow interacting with it using a std.stdio.File.

XAttrs
struct XAttrs(Obj, string funPrefix)

AA-like object for accessing a file's extended attributes.

Templates

listDir
template listDir(alias handler, Flag!q{includeRoot} includeRoot = No.includeRoot)

Fast templated directory iterator

mdFile
template mdFile()

Calculate the MD5 hash of a file.

mdFileCached
template mdFileCached()

Calculate the MD5 hash of a file, and memoize it.

withTarget
template withTarget(alias targetGen, alias fun)

Composes a function which generates a file name with a function which creates the file. Returns the file name.

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>