MiKTeX 23.10-next
A scalable TeX distribution
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
MiKTeX::Core::File Class Reference

#include <miktex/Core/File.h>

Public Types

enum class  LockType { Shared , Exclusive }
 File lock type. More...
 

Public Member Functions

 File (const File &other)=delete
 
Fileoperator= (const File &other)=delete
 
 File (File &&other)=delete
 
Fileoperator= (File &&other)=delete
 

Static Public Member Functions

static void Delete (const MiKTeX::Util::PathName &path, FileDeleteOptionSet options)
 
static void Delete (const MiKTeX::Util::PathName &path)
 
static bool Exists (const MiKTeX::Util::PathName &path, FileExistsOptionSet options)
 
static bool Exists (const MiKTeX::Util::PathName &path)
 
static FileAttributeSet GetAttributes (const MiKTeX::Util::PathName &path)
 
static unsigned long GetNativeAttributes (const MiKTeX::Util::PathName &path)
 
static std::size_t GetSize (const MiKTeX::Util::PathName &path)
 
static void Move (const MiKTeX::Util::PathName &source, const MiKTeX::Util::PathName &dest, FileMoveOptionSet option)
 
static void Move (const MiKTeX::Util::PathName &source, const MiKTeX::Util::PathName &dest)
 
static void Copy (const MiKTeX::Util::PathName &source, const MiKTeX::Util::PathName &dest, FileCopyOptionSet options)
 
static void Copy (const MiKTeX::Util::PathName &source, const MiKTeX::Util::PathName &dest)
 
static void CreateLink (const MiKTeX::Util::PathName &oldName, const MiKTeX::Util::PathName &newName, CreateLinkOptionSet options)
 
static bool IsSymbolicLink (const MiKTeX::Util::PathName &path)
 
static MiKTeX::Util::PathName ReadSymbolicLink (const MiKTeX::Util::PathName &path)
 
static bool Equals (const MiKTeX::Util::PathName &path1, const MiKTeX::Util::PathName &path2)
 
static size_t SetMaxOpen (size_t newMax)
 
static FILE * Open (const MiKTeX::Util::PathName &path, FileMode mode, FileAccess access)
 
static FILE * Open (const MiKTeX::Util::PathName &path, FileMode mode, FileAccess access, bool isTextFile)
 
static FILE * Open (const MiKTeX::Util::PathName &path, FileMode mode, FileAccess access, bool isTextFile, FileOpenOptionSet options)
 
static std::ifstream CreateInputStream (const MiKTeX::Util::PathName &path, std::ios_base::openmode mode, std::ios_base::iostate exceptions)
 
static std::ifstream CreateInputStream (const MiKTeX::Util::PathName &path)
 
static std::ofstream CreateOutputStream (const MiKTeX::Util::PathName &path, std::ios_base::openmode mode, std::ios_base::iostate exceptions)
 
static std::ofstream CreateOutputStream (const MiKTeX::Util::PathName &path, std::ios_base::openmode mode)
 
static std::ofstream CreateOutputStream (const MiKTeX::Util::PathName &path)
 
static void SetAttributes (const MiKTeX::Util::PathName &path, FileAttributeSet attributes)
 
static void SetNativeAttributes (const MiKTeX::Util::PathName &path, unsigned long nativeAttributes)
 
static void SetTimes (int fd, time_t creationTime, time_t lastAccessTime, time_t lastWriteTime)
 
static void SetTimes (FILE *file, time_t creationTime, time_t lastAccessTime, time_t lastWriteTime)
 
static void SetTimes (const MiKTeX::Util::PathName &path, time_t creationTime, time_t lastAccessTime, time_t lastWriteTime)
 
static void GetTimes (const MiKTeX::Util::PathName &path, time_t &creationTime, time_t &lastAccessTime, time_t &lastWriteTime)
 
static time_t GetLastWriteTime (const MiKTeX::Util::PathName &path)
 
static std::vector< unsigned char > ReadAllBytes (const MiKTeX::Util::PathName &path)
 
static void WriteBytes (const MiKTeX::Util::PathName &path, const std::vector< unsigned char > &data)
 
static bool TryLock (int fd, LockType lockType, std::chrono::milliseconds timeout)
 
static bool TryLock (FILE *file, LockType lockType, std::chrono::milliseconds timeout)
 
static bool TryLock (HANDLE hFile, LockType lockType, std::chrono::milliseconds timeout)
 
static void Unlock (int fd)
 
static void Unlock (FILE *file)
 
static void Unlock (HANDLE hFile)
 

Detailed Description

File class.

This is a static class which offers file operations.

Member Enumeration Documentation

◆ LockType

enum class MiKTeX::Core::File::LockType
strong

File lock type.

Enumerator
Shared 

Shared lock.

Exclusive 

Exclusive lock.

Member Function Documentation

◆ Copy() [1/2]

static void MiKTeX::Core::File::Copy ( const MiKTeX::Util::PathName source,
const MiKTeX::Util::PathName dest 
)
inlinestatic

Copies a file.

Parameters
sourceThe file system path to the source file.
destThe file system path to the destination file.

◆ Copy() [2/2]

static void MiKTeX::Core::File::Copy ( const MiKTeX::Util::PathName source,
const MiKTeX::Util::PathName dest,
FileCopyOptionSet  options 
)
static

Copies a file.

Parameters
sourceThe file system path to the source file.
destThe file system path to the destination file.
optionsOptions for copying the file.

◆ CreateInputStream() [1/2]

static std::ifstream MiKTeX::Core::File::CreateInputStream ( const MiKTeX::Util::PathName path)
inlinestatic

Opens an input stream on a file.

Parameters
pathThe file system path to the file.
Returns
Returns an ifstream object.

◆ CreateInputStream() [2/2]

static std::ifstream MiKTeX::Core::File::CreateInputStream ( const MiKTeX::Util::PathName path,
std::ios_base::openmode  mode,
std::ios_base::iostate  exceptions 
)
static

Opens an input stream on a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is open.
exceptionsSpecifies the exceptions to be thrown if an error occurs.
Returns
Returns an ifstream object.

◆ CreateLink()

static void MiKTeX::Core::File::CreateLink ( const MiKTeX::Util::PathName oldName,
const MiKTeX::Util::PathName newName,
CreateLinkOptionSet  options 
)
static

Creates a file system link.

Parameters
oldNameThe file system path to the existing file.
newNameThe file system path to link.
optionsOptions for creating the link.

◆ CreateOutputStream() [1/3]

static std::ofstream MiKTeX::Core::File::CreateOutputStream ( const MiKTeX::Util::PathName path)
inlinestatic

Opens an output stream on a file.

Parameters
pathThe file system path to the file.
Returns
Returns an ofstream object.

◆ CreateOutputStream() [2/3]

static std::ofstream MiKTeX::Core::File::CreateOutputStream ( const MiKTeX::Util::PathName path,
std::ios_base::openmode  mode 
)
inlinestatic

Opens an output stream on a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is to open.
Returns
Returns an ofstream object.

◆ CreateOutputStream() [3/3]

static std::ofstream MiKTeX::Core::File::CreateOutputStream ( const MiKTeX::Util::PathName path,
std::ios_base::openmode  mode,
std::ios_base::iostate  exceptions 
)
static

Opens an output stream on a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is to open.
exceptionsSpecifies the exceptions to be thrown if an error occurs.
Returns
Returns an ofstream object.

◆ Delete() [1/2]

static void MiKTeX::Core::File::Delete ( const MiKTeX::Util::PathName path)
static

Deletes a file.

Parameters
pathFile system path to the file.

◆ Delete() [2/2]

static void MiKTeX::Core::File::Delete ( const MiKTeX::Util::PathName path,
FileDeleteOptionSet  options 
)
static

Deletes a file.

Parameters
pathFile system path to the file.
optionsOptions for deleting the file.

◆ Equals()

static bool MiKTeX::Core::File::Equals ( const MiKTeX::Util::PathName path1,
const MiKTeX::Util::PathName path2 
)
static

Test equality of two files.

Parameters
path1The file system path to the first file.
path2The file system path to the second file.
Returns
Returns true, if both files compare equal.

◆ Exists() [1/2]

static bool MiKTeX::Core::File::Exists ( const MiKTeX::Util::PathName path)
static

Tests if a file exists.

Parameters
pathFile system path to the file.

◆ Exists() [2/2]

static bool MiKTeX::Core::File::Exists ( const MiKTeX::Util::PathName path,
FileExistsOptionSet  options 
)
static

Tests if a file exists.

Parameters
pathFile system path to the file.
optionsOptions for checking the existance.

◆ GetAttributes()

static FileAttributeSet MiKTeX::Core::File::GetAttributes ( const MiKTeX::Util::PathName path)
static

Get attributes of a file.

Parameters
pathFile system path to the file.
Returns
Returns the attributes of the file.
See also
SetAttributes

◆ GetLastWriteTime()

static time_t MiKTeX::Core::File::GetLastWriteTime ( const MiKTeX::Util::PathName path)
inlinestatic

Gets the modification timestamp of a file.

Parameters
pathThe file system path to the file.
[out]creationTimeCreation timestamp.
[out]lastAccessTimeLast access timestamp.
[out]lastWriteTimeLast modification timestamp.

◆ GetNativeAttributes()

static unsigned long MiKTeX::Core::File::GetNativeAttributes ( const MiKTeX::Util::PathName path)
static

Get native (operating system) attributes of a file.

Parameters
pathFile system path to the file.
Returns
Returns the native attributes of the file.
See also
SetNativeAttributes

◆ GetSize()

static std::size_t MiKTeX::Core::File::GetSize ( const MiKTeX::Util::PathName path)
static

Gets the size of a file.

Parameters
pathFile system path to the file.
Returns
Returns the size (in bytes) of the file.

◆ GetTimes()

static void MiKTeX::Core::File::GetTimes ( const MiKTeX::Util::PathName path,
time_t &  creationTime,
time_t &  lastAccessTime,
time_t &  lastWriteTime 
)
static

Gets file timestamps.

Parameters
pathThe file system path to the file.
[out]creationTimeCreation timestamp.
[out]lastAccessTimeLast access timestamp.
[out]lastWriteTimeLast modification timestamp.

◆ IsSymbolicLink()

static bool MiKTeX::Core::File::IsSymbolicLink ( const MiKTeX::Util::PathName path)
static

Tests if a file is a symbolic link.

Parameters
pathThe file system path to the file.
Returns
Returns true, if the file is a symbolic link.

◆ Move() [1/2]

static void MiKTeX::Core::File::Move ( const MiKTeX::Util::PathName source,
const MiKTeX::Util::PathName dest 
)
inlinestatic

Renames (moves) a file.

Parameters
sourceThe file system path to the source file.
destThe file system path to the destination file.

◆ Move() [2/2]

static void MiKTeX::Core::File::Move ( const MiKTeX::Util::PathName source,
const MiKTeX::Util::PathName dest,
FileMoveOptionSet  option 
)
static

Renames (moves) a file.

Parameters
sourceThe file system path to the source file.
destThe file system path to the destination file.
optionsOptions for renaming the file.

◆ Open() [1/3]

static FILE * MiKTeX::Core::File::Open ( const MiKTeX::Util::PathName path,
FileMode  mode,
FileAccess  access 
)
static

Opens a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is to open.
accessSpecifies how the file will be accessed.
Returns
Returns the pointer to a FILE object.

◆ Open() [2/3]

static FILE * MiKTeX::Core::File::Open ( const MiKTeX::Util::PathName path,
FileMode  mode,
FileAccess  access,
bool  isTextFile 
)
static

Opens a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is to open.
accessSpecifies how the file will be accessed.
isTextFileSpecifies if the file should be opened in text mode.
Returns
Returns the pointer to a FILE object.

◆ Open() [3/3]

static FILE * MiKTeX::Core::File::Open ( const MiKTeX::Util::PathName path,
FileMode  mode,
FileAccess  access,
bool  isTextFile,
FileOpenOptionSet  options 
)
static

Opens a file.

Parameters
pathThe file system path to the file.
modeSpecifies how the file is to open.
accessSpecifies how the file will be accessed.
isTextFileSpecifies if the file should be opened in text mode.
optionsOptions for opening the file.
Returns
Returns the pointer to a FILE object.

◆ ReadAllBytes()

static std::vector< unsigned char > MiKTeX::Core::File::ReadAllBytes ( const MiKTeX::Util::PathName path)
static

Reads a file.

Parameters
pathThe file system path to the file.
Returns
Returns the file contents.

◆ ReadSymbolicLink()

static MiKTeX::Util::PathName MiKTeX::Core::File::ReadSymbolicLink ( const MiKTeX::Util::PathName path)
static

Follows a symbolic link.

Parameters
pathThe file system path to the link.
Returns
Returns the file system path to the link target.

◆ SetAttributes()

static void MiKTeX::Core::File::SetAttributes ( const MiKTeX::Util::PathName path,
FileAttributeSet  attributes 
)
static

Sets file attributes.

Parameters
pathThe file system path to the file.
attributesThe attributes to set.
See also
GetAttributes

◆ SetMaxOpen()

static size_t MiKTeX::Core::File::SetMaxOpen ( size_t  newMax)
static

Sets the maximum number of simultaneously open files.

Todo:
To be removed

◆ SetNativeAttributes()

static void MiKTeX::Core::File::SetNativeAttributes ( const MiKTeX::Util::PathName path,
unsigned long  nativeAttributes 
)
static

Sets native (OS) file attributes.

Parameters
pathThe file system path to the file.
attributesThe native attributes to set.
See also
GetNativeAttributes

◆ SetTimes() [1/3]

static void MiKTeX::Core::File::SetTimes ( const MiKTeX::Util::PathName path,
time_t  creationTime,
time_t  lastAccessTime,
time_t  lastWriteTime 
)
static

Sets file timestamps.

Parameters
pathThe file system path to the file.
creationTimeCreation timestamp.
lastAccessTimeLast access timestamp.
lastWriteTimeLast modification timestamp.

◆ SetTimes() [2/3]

static void MiKTeX::Core::File::SetTimes ( FILE *  file,
time_t  creationTime,
time_t  lastAccessTime,
time_t  lastWriteTime 
)
static

Sets file timestamps.

Parameters
fileThe pointer to the FILE object.
creationTimeCreation timestamp.
lastAccessTimeLast access timestamp.
lastWriteTimeLast modification timestamp.

◆ SetTimes() [3/3]

static void MiKTeX::Core::File::SetTimes ( int  fd,
time_t  creationTime,
time_t  lastAccessTime,
time_t  lastWriteTime 
)
static

Sets file timestamps.

Parameters
fdThe file descriptor.
creationTimeCreation timestamp.
lastAccessTimeLast access timestamp.
lastWriteTimeLast modification timestamp.

◆ TryLock() [1/3]

static bool MiKTeX::Core::File::TryLock ( FILE *  file,
LockType  lockType,
std::chrono::milliseconds  timeout 
)
inlinestatic

Tries to lock a file.

Parameters
fileThe pointer to a FILE object.
lockTypeThe requested lock type.
timeoutThe maximum time waited for the file lock.
Returns
Returns true, if the file could be locked.

◆ TryLock() [2/3]

static bool MiKTeX::Core::File::TryLock ( HANDLE  hFile,
LockType  lockType,
std::chrono::milliseconds  timeout 
)
static

Tries to lock a file.

Parameters
hFileThe file HANDLE.
lockTypeThe requested lock type.
timeoutThe maximum time waited for the file lock.
Returns
Returns true, if the file could be locked.

◆ TryLock() [3/3]

static bool MiKTeX::Core::File::TryLock ( int  fd,
LockType  lockType,
std::chrono::milliseconds  timeout 
)
static

Tries to lock a file.

Parameters
fdThe file descriptor.
lockTypeThe requested lock type.
timeoutThe maximum time waited for the file lock.
Returns
Returns true, if the file could be locked.

◆ Unlock() [1/3]

static void MiKTeX::Core::File::Unlock ( FILE *  file)
inlinestatic

Unlocks a locked file.

Parameters
fileThe pointer to a FILE object.

◆ Unlock() [2/3]

static void MiKTeX::Core::File::Unlock ( HANDLE  hFile)
static

Unlocks a locked file.

Parameters
hFileThe file HANDLE.

◆ Unlock() [3/3]

static void MiKTeX::Core::File::Unlock ( int  fd)
static

Unlocks a locked file.

Parameters
fdThe file descriptor.

◆ WriteBytes()

static void MiKTeX::Core::File::WriteBytes ( const MiKTeX::Util::PathName path,
const std::vector< unsigned char > &  data 
)
static

Write a file.

Parameters
pathThe file system path to the file.
Thefile contents.

The documentation for this class was generated from the following file: