Base Framework
Classes | Public Types | Static Public Member Functions | Static Public Attributes | List of all members
FileSystem Class Reference

File system. More...

#include <base/filesystem/FileSystem.h>

Inherits Object.

Classes

class  Quota
 

Public Types

enum  {
  BLOCK = 1, CHARACTER = 2, DEVICE = 1024, FIFO = 4,
  FOLDER = 8, LINK = 16, MESSAGE_QUEUE = 32, REGULAR = 64,
  SOCKET = 128, SEMPAHORE = 256, SHARED_MEMORY = 512
}
 
enum  TemporaryFolder { USER_SPECIFIED, MACHINE_NONPERSISTENT, MACHINE_PERSISTENT }
 
enum  TemporaryFileNameField {
  PREFIX = 1, USER = 2, APPLICATION = 4, PROCESS = 8,
  HOST = 16, COUNTER = 32, TIME = 64, RANDOM = 128,
  SUFFIX = 256
}
 
enum  TemporaryFileOption {
  STRICT_ACCESS = 1, OVERWRITE_ON_CLOSE = 2, REMOVE_ON_CLOSE = 4, EXCLUSIVE = 8,
  SECURE = STRICT_ACCESS | OVERWRITE_ON_CLOSE | REMOVE_ON_CLOSE
}
 
enum  Component {
  FOLDER_PATH, FILENAME, NAME, DOTEXTENSION,
  EXTENSION
}
 
enum  Variable {
  MIN_FILE_SIZE_BITS, MAX_NUM_OF_LINKS, MAX_LEN_OF_NAME, MAX_LEN_OF_PATH,
  MAX_SIZE_OF_PIPE_BUFFER, MAX_SIZE_OF_SYMLINK
}
 
enum  Folder { ROOT, DEVICES, TEMP }
 

Static Public Member Functions

static bool isSeparator (ucs4 ch) noexcept
 
static MemoryDiff findSeparator (const String &path, MemorySize start)
 
static MemoryDiff findLastSeparator (const String &path)
 
static String getPath (const String &base, const String &relative) noexcept
 
static String join (const String &base, const String &relative) noexcept
 
static String join (const std::initializer_list< String > &paths) noexcept
 
static String getComponent (const String &path, Component component)
 
static bool isAbsolutePath (const String &path) noexcept
 
static bool isFolderPath (const String &path) noexcept
 
static String toAbsolutePath (const String &base, const String &path)
 
static String findFile (const Array< String > &searchPaths, const String &relative, unsigned int index=0)
 
static String toUrl (const String &path)
 
static String getCurrentFolder ()
 
static void setCurrentFolder (const String &path)
 
static unsigned int getType (const String &path)
 
static uint64 getSize (const String &path)
 
static bool entryExists (const String &path)
 
static bool fileExists (const String &path)
 
static bool folderExists (const String &path)
 
static void removeFile (const String &path)
 
static void removeFolder (const String &path)
 
static void makeFolder (const String &path)
 
static void makeFolderRecursive (const String &path)
 
static bool doesSupportLinks () noexcept
 
static void makeHardLink (const String &target, const String &destination)
 
static bool isLink (const String &path)
 
static void makeLink (const String &target, const String &destination)
 
static String getLinkTarget (const String &path)
 
static String getTempFolder (TemporaryFolder folder=USER_SPECIFIED) noexcept
 
static String getTempFileName (unsigned int fields=PREFIX|APPLICATION|USER|SUFFIX) noexcept
 
static File getTempFile (unsigned int options=SECURE)
 
static unsigned long getVariable (const String &path, Variable variable)
 
static String getFolder (Folder folder) noexcept
 
static String getRelativePath (const String &folder, const String &path)
 
static String getParent (const String &path)
 
static Array< Stringsplit (const String &path)
 
static String join (const Array< String > &paths)
 
static String normalize (const String &path)
 
static Quota getQuota (const String &path, Trustee trustee)
 

Static Public Attributes

static const unsigned int MAXIMUM_PATH_LENGTH
 

Detailed Description

File system.

File system.

Version
1.1

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

File system entry type.

Enumerator
BLOCK 

Block.

CHARACTER 

Character.

DEVICE 

Device.

FIFO 

Fifo.

FOLDER 

Folder.

LINK 

Link.

MESSAGE_QUEUE 

Message queue.

REGULAR 

Regular.

SOCKET 

Socket.

SEMPAHORE 

Semaphore.

SHARED_MEMORY 

Shared memory.

◆ Component

Enumerator
FOLDER_PATH 

The folder with an ending separator (i.e. '/' or '\').

FILENAME 

The name and extension.

NAME 

The name of the entry excluding the extension and dot.

DOTEXTENSION 

The extension (including the dot).

EXTENSION 

The extension (excluding the dot).

◆ Folder

System folders.

Enumerator
ROOT 

The root folder.

DEVICES 

The folder intended for devices.

TEMP 

Folder intended for temporary files of applications. The files are not guaranteed to be preserved between application invocations.

◆ TemporaryFileNameField

The fields of a temporary file.

Enumerator
PREFIX 

Add the prefix '~'.

USER 

Add the user name.

APPLICATION 

Add the formal name of application.

PROCESS 

Add the process id.

HOST 

Add the host name.

COUNTER 

Add internal counter (and increment the counter).

TIME 

Add the current time.

RANDOM 

Add a random number.

SUFFIX 

Add the suffix '.tmp'.

◆ TemporaryFileOption

Temporary file options.

Enumerator
STRICT_ACCESS 

Sets the access control of the file such that only the owner of the process has access to it.

OVERWRITE_ON_CLOSE 

The content of the file is overwritten when the file is closed (this implies REMOVE_ON_CLOSE).

REMOVE_ON_CLOSE 

The file is removed when closed.

EXCLUSIVE 

The file is opened in exclusive mode.

SECURE 

The file is opened in secure mode.

◆ TemporaryFolder

The temporary folder.

Enumerator
USER_SPECIFIED 

Uses the temporary folder specified by the 'TMP' environment variable. If the variable doesn't exist the TEMP variable is used. If neither are defined this falls back on MACHINE_NONPERSISTENT.

MACHINE_NONPERSISTENT 

Specifies the temporary folder intended for non-persistent temporary files.

MACHINE_PERSISTENT 

Specifies the temporary folder intended for persistent temporary files.

◆ Variable

File system variables.

Enumerator
MIN_FILE_SIZE_BITS 

Specifies the minimum number of bits required to represent the maximum supported file size.

MAX_NUM_OF_LINKS 

Specifies the maximum number of links to a file.

MAX_LEN_OF_NAME 

Specifies the maximum length of a file name.

MAX_LEN_OF_PATH 

Specifies the maximum length of a path.

MAX_SIZE_OF_PIPE_BUFFER 

Specifies the maximum number bytes that is guaranteed to be atomic when writing to a pipe.

MAX_SIZE_OF_SYMLINK 

Specifies the maximum number of bytes in a symbolic link.

Member Function Documentation

◆ doesSupportLinks()

static bool FileSystem::doesSupportLinks ( )
staticnoexcept

Returns true if symbolic links are supported. This method always returns true for Unices.

Examples
testsuite/ln.cpp.

◆ entryExists()

static bool FileSystem::entryExists ( const String path)
static

Returns true if the entry exists.

Examples
testsuite/ln.cpp, and testsuite/rm.cpp.

◆ fileExists()

static bool FileSystem::fileExists ( const String path)
static

Returns true if the file exists.

◆ findFile()

static String FileSystem::findFile ( const Array< String > &  searchPaths,
const String relative,
unsigned int  index = 0 
)
static

Returns the absolute path of the first file found.

Parameters
searchPathsThe search paths.
relativeThe relative path (SHOULD not be absolute).
indexSpecifies the first index in the searchPaths. The default is 0.
Returns
Empty string if not found. The relative path if it is really an absolute path.

◆ findLastSeparator()

static MemoryDiff FileSystem::findLastSeparator ( const String path)
static

Returns the index of the last separator. For Windows both \ and / are separator.

Returns -1 is not found.

◆ findSeparator()

static MemoryDiff FileSystem::findSeparator ( const String path,
MemorySize  start 
)
static

Returns the index of the first separator. For Windows both \ and / are separator.

Returns -1 is not found.

◆ folderExists()

static bool FileSystem::folderExists ( const String path)
static

Returns true if the folder exists.

Examples
testsuite/du.cpp, and testsuite/ls.cpp.

◆ getComponent()

static String FileSystem::getComponent ( const String path,
Component  component 
)
static

Returns the specified component of the path.

Parameters
pathThe path.
componentThe desired component (FOLDER_PATH, NAME, EXTENSION, ...).
Examples
testsuite/ln.cpp.

◆ getCurrentFolder()

static String FileSystem::getCurrentFolder ( )
static

Returns the path of the current folder.

◆ getFolder()

static String FileSystem::getFolder ( Folder  folder)
staticnoexcept

Returns the path to the specified folder.

◆ getLinkTarget()

static String FileSystem::getLinkTarget ( const String path)
static

Returns the target of the symbolic link.

Parameters
pathThe path of the symbolic link.
Examples
testsuite/ls.cpp.

◆ getParent()

static String FileSystem::getParent ( const String path)
static

Returns the parent folder.

◆ getPath()

static String FileSystem::getPath ( const String base,
const String relative 
)
staticnoexcept

Returns the combined path of the specified base and relative path.

Parameters
baseThe base path.
relativeThe relative path.
Returns
the relative path if base is blank.
Examples
testsuite/du.cpp.

◆ getQuota()

static Quota FileSystem::getQuota ( const String path,
Trustee  trustee 
)
static

Returns the quota.

Parameters
pathThe path to the device.
trusteeThe truestee.
Examples
testsuite/Quota.cpp.

◆ getRelativePath()

static String FileSystem::getRelativePath ( const String folder,
const String path 
)
static

Returns the relative path to the given folder.

getRelativePath("a/b/c/d/e/f", "a/b/c/g/h/i") returns "../../../g/h/i".

◆ getSize()

static uint64 FileSystem::getSize ( const String path)
static

Returns the size of the specified file.

Examples
testsuite/du.cpp.

◆ getTempFile()

static File FileSystem::getTempFile ( unsigned int  options = SECURE)
static

Returns a temporary file.

Parameters
optionsThe file options. The default is SECURE.

◆ getTempFileName()

static String FileSystem::getTempFileName ( unsigned int  fields = PREFIX|APPLICATION|USER|SUFFIX)
staticnoexcept

Generates a temporary file name. The returned name should be used in conjuction with a folder path returned by getTempFolder or other folder path. Every field is separated by a '-' except for the PREFIX and SUFFIX. The order of the fields are fixed and given by the order of the fields within the enumeration TemporaryFileNameField.

Parameters
fieldsSpecifies the fields to include in the name. The default is PREFIX|APPLICATION|USER|SUFFIX.

◆ getTempFolder()

static String FileSystem::getTempFolder ( TemporaryFolder  folder = USER_SPECIFIED)
staticnoexcept

Returns the path to the folder intended for temporary files.

Parameters
folderSpecifies the folder to be used. The default is USER_SPECIFIED.

◆ getType()

static unsigned int FileSystem::getType ( const String path)
static

Returns the file system flags describing the specified entry.

Examples
testsuite/digest.cpp, testsuite/du.cpp, testsuite/ls.cpp, and testsuite/rm.cpp.

◆ getVariable()

static unsigned long FileSystem::getVariable ( const String path,
Variable  variable 
)
static

Returns the value of the specified file system variable.

◆ isAbsolutePath()

static bool FileSystem::isAbsolutePath ( const String path)
staticnoexcept

Returns true if the specifies path is an absolute path.

◆ isFolderPath()

static bool FileSystem::isFolderPath ( const String path)
inlinestaticnoexcept

Returns true if the specified path is a explicit folder path (i.e. ends with the separator).

◆ isLink()

static bool FileSystem::isLink ( const String path)
static

Returns true if the file object specified by the path is a symbolic link.

Returns
False if the path doesn't point to an object.
Examples
testsuite/ls.cpp.

◆ isSeparator()

static bool FileSystem::isSeparator ( ucs4  ch)
inlinestaticnoexcept

Returns true if char is a separator. For Windows both \ and / are separator.

◆ join() [1/3]

static String FileSystem::join ( const Array< String > &  paths)
static

Joins the paths.

◆ join() [2/3]

static String FileSystem::join ( const std::initializer_list< String > &  paths)
staticnoexcept

Returns the combined path of the specified base and relative path.

Parameters
pathsThe paths to join.

◆ join() [3/3]

static String FileSystem::join ( const String base,
const String relative 
)
inlinestaticnoexcept

Returns the combined path of the specified base and relative path.

Parameters
baseThe base path.
relativeThe relative path.
Returns
Returns the relative path if base is blank.

◆ makeFolder()

static void FileSystem::makeFolder ( const String path)
static

Makes a folder.

◆ makeFolderRecursive()

static void FileSystem::makeFolderRecursive ( const String path)
static

Makes a folder.

◆ makeHardLink()

static void FileSystem::makeHardLink ( const String target,
const String destination 
)
static

Creates a hard link.

Parameters
targetThe target of the link.
destinationThe path of the destination file/folder.

◆ makeLink()

static void FileSystem::makeLink ( const String target,
const String destination 
)
static

Creates a symbolic link.

Parameters
targetThe target of the link.
destinationThe path of the destination file/folder.
Examples
testsuite/ln.cpp.

◆ normalize()

static String FileSystem::normalize ( const String path)
static

Returns the normalized path.

◆ removeFile()

static void FileSystem::removeFile ( const String path)
static

Removes the specified file.

Examples
testsuite/rm.cpp.

◆ removeFolder()

static void FileSystem::removeFolder ( const String path)
static

Removes the specified folder. The folder must be empty.

Examples
testsuite/rm.cpp.

◆ setCurrentFolder()

static void FileSystem::setCurrentFolder ( const String path)
static

Sets the current folder.

Examples
testsuite/digest.cpp, and testsuite/ls.cpp.

◆ split()

static Array<String> FileSystem::split ( const String path)
static

Returns the path split into sections.

Separators are not included in result except the first item it is is to indicate root.

◆ toAbsolutePath()

static String FileSystem::toAbsolutePath ( const String base,
const String path 
)
static

Converts the path to an absolute path.

Parameters
baseThe base path.
pathThe path to be converted.

◆ toUrl()

static String FileSystem::toUrl ( const String path)
static

Returns a URL from the specified path. The URL has the following format: "file:///C:/WINNT" or "file:///usr/local".

Parameters
pathThe path to convert to a URL (MUST be absolute).

Member Data Documentation

◆ MAXIMUM_PATH_LENGTH

const unsigned int FileSystem::MAXIMUM_PATH_LENGTH
static

Specifies the maximum length of a path.