Doxygen
Loading...
Searching...
No Matches
Dir Class Referencefinal

Class representing a directory in the file system. More...

#include <src/dir.h>

Classes

struct  Private

Public Member Functions

 Dir ()
 Dir (const std::string &path)
 Dir (const Dir &d)
Dir & operator= (const Dir &d)
 Dir (Dir &&d)
Dir & operator= (Dir &&d)
 ~Dir ()
void setPath (const std::string &path)
std::string path () const
DirIterator iterator () const
bool empty (const std::string &subdir) const
bool exists () const
std::string filePath (const std::string &path, bool acceptsAbsPath=true) const
bool exists (const std::string &path, bool acceptsAbsPath=true) const
bool mkdir (const std::string &path, bool acceptsAbsPath=true) const
bool rmdir (const std::string &path, bool acceptsAbsPath=true) const
bool remove (const std::string &path, bool acceptsAbsPath=true) const
bool rename (const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
bool copy (const std::string &src, const std::string &dest, bool acceptsAbsPath=true) const
std::string absPath () const
bool isRelative () const

Static Public Member Functions

static bool isRelativePath (const std::string &path)
static std::string currentDirPath ()
static bool setCurrent (const std::string &path)
static std::string cleanDirPath (const std::string &path)

Private Attributes

std::unique_ptr< Private > p

Detailed Description

Class representing a directory in the file system.

Definition at line 72 of file dir.h.

Constructor & Destructor Documentation

◆ Dir() [1/4]

Dir::Dir ( )

Definition at line 194 of file dir.cpp.

194 : p(std::make_unique<Private>())
195{
196 std::error_code ec;
197 p->path = fs::current_path(ec);
198}
std::unique_ptr< Private > p
Definition dir.h:108

References p.

Referenced by Dir(), Dir(), operator=(), and operator=().

◆ Dir() [2/4]

Dir::Dir ( const std::string & path)

Definition at line 225 of file dir.cpp.

225 : p(std::make_unique<Private>())
226{
227 setPath(path);
228}
void setPath(const std::string &path)
Definition dir.cpp:234
std::string path() const
Definition dir.cpp:239

References p, path(), and setPath().

◆ Dir() [3/4]

Dir::Dir ( const Dir & d)

Definition at line 200 of file dir.cpp.

200 : p(std::make_unique<Private>())
201{
202 p->path = d.p->path;
203}

References Dir(), and p.

◆ Dir() [4/4]

Dir::Dir ( Dir && d)

Definition at line 214 of file dir.cpp.

214 : p(std::make_unique<Private>())
215{
216 std::exchange(p->path,d.p->path);
217}

References Dir(), and p.

◆ ~Dir()

Dir::~Dir ( )

Definition at line 230 of file dir.cpp.

231{
232}

Member Function Documentation

◆ absPath()

std::string Dir::absPath ( ) const

Definition at line 369 of file dir.cpp.

370{
371 std::error_code ec;
372 std::string result = fromFsPath(fs::absolute(p->path,ec));
373 correctPath(result);
374 return result;
375}
static void correctPath(std::string &s)
Definition dir.cpp:249
std::string fromFsPath(const fs::path &p)
Converts a path into a UTF-8 encoded string.
Definition fswrapper.h:78

References correctPath(), fromFsPath(), and p.

Referenced by Htags::execute(), PerlModGenerator::generate(), FormulaManager::generateImages(), parseInput(), Htags::path2URL(), RTFGenerator::preProcessFileInplace(), writeDotGraphFromFile(), writeDotImageMapFromFile(), and DotGraph::writeGraph().

◆ cleanDirPath()

std::string Dir::cleanDirPath ( const std::string & path)
static

Definition at line 362 of file dir.cpp.

363{
364 std::string result = fromFsPath(toFsPath(path).lexically_normal());
365 correctPath(result);
366 return result;
367}
fs::path toFsPath(const std::string &s)
Converts a UTF-8 encoded string into a path.
Definition fswrapper.h:64

References correctPath(), fromFsPath(), path(), and toFsPath().

Referenced by FileNameLinkedMap::findFileDef(), resolveSymlink(), and FileNameLinkedMap::showFileDefMatches().

◆ copy()

bool Dir::copy ( const std::string & src,
const std::string & dest,
bool acceptsAbsPath = true ) const

Definition at line 335 of file dir.cpp.

336{
337 const auto &copyOptions = fs::copy_options::overwrite_existing;
338 std::error_code ec, ec_perm;
339 std::string sn = filePath(srcName,acceptsAbsPath);
340 std::string dn = filePath(dstName,acceptsAbsPath);
341 fs::copy(toFsPath(sn),toFsPath(dn),copyOptions,ec);
342 // make sure the destination is writable for the owner (see issue #11600)
343 fs::permissions(toFsPath(dn), fs::perms::owner_write, fs::perm_options::add, ec_perm);
344 return !ec;
345}
std::string filePath(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:285

References filePath(), and toFsPath().

◆ currentDirPath()

std::string Dir::currentDirPath ( )
static

◆ empty()

bool Dir::empty ( const std::string & subdir) const

Definition at line 268 of file dir.cpp.

269{
270 fs::path pth = p->path;
271 pth /= toFsPath(subdir);
272 return fs::is_empty(pth);
273}

References p, and toFsPath().

Referenced by clearSubDirs().

◆ exists() [1/2]

◆ exists() [2/2]

bool Dir::exists ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 254 of file dir.cpp.

255{
256 std::string result = filePath(path,acceptsAbsPath);
257 std::error_code ec;
258 bool exist = fs::exists(toFsPath(result),ec);
259 return !ec && exist;
260}

References filePath(), path(), and toFsPath().

◆ filePath()

std::string Dir::filePath ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 285 of file dir.cpp.

286{
287 std::string result;
288 if (acceptsAbsPath && !isRelativePath(path))
289 {
290 result = path;
291 }
292 else
293 {
294 result = fromFsPath(p->path / toFsPath(path));
295 }
296 correctPath(result);
297 return result;
298}
static bool isRelativePath(const std::string &path)
Definition dir.cpp:280

References correctPath(), fromFsPath(), isRelativePath(), p, path(), and toFsPath().

Referenced by copy(), exists(), mkdir(), preProcessFile(), RTFGenerator::preProcessFileInplace(), remove(), and rename().

◆ isRelative()

bool Dir::isRelative ( ) const

Definition at line 275 of file dir.cpp.

276{
277 return p->path.is_relative();
278}

References p.

◆ isRelativePath()

bool Dir::isRelativePath ( const std::string & path)
static

Definition at line 280 of file dir.cpp.

281{
282 return toFsPath(path).is_relative();
283}

References path(), and toFsPath().

Referenced by filePath().

◆ iterator()

DirIterator Dir::iterator ( ) const

Definition at line 244 of file dir.cpp.

245{
246 return DirIterator(fromFsPath(p->path));
247}

References fromFsPath(), and p.

Referenced by readDir().

◆ mkdir()

bool Dir::mkdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 300 of file dir.cpp.

301{
302 std::error_code ec;
303 std::string result = filePath(path,acceptsAbsPath);
304 if (exists(path,acceptsAbsPath))
305 {
306 return true;
307 }
308 else
309 {
310 return fs::create_directory(toFsPath(result),ec);
311 }
312}
bool exists() const
Definition dir.cpp:262

References exists(), filePath(), path(), and toFsPath().

Referenced by PerlModGenerator::createOutputDir(), createOutputDirectory(), createSubDirs(), generateDEF(), generateOutput(), CitationManager::generatePage(), DocbookGenerator::init(), HtmlGenerator::init(), LatexGenerator::init(), ManGenerator::init(), RTFGenerator::init(), initWarningFormat(), and parseInput().

◆ operator=() [1/2]

Dir & Dir::operator= ( const Dir & d)

Definition at line 205 of file dir.cpp.

206{
207 if (&d!=this)
208 {
209 p->path = d.p->path;
210 }
211 return *this;
212}

References Dir(), and p.

◆ operator=() [2/2]

Dir & Dir::operator= ( Dir && d)

Definition at line 219 of file dir.cpp.

220{
221 std::exchange(p->path,d.p->path);
222 return *this;
223}

References Dir(), and p.

◆ path()

std::string Dir::path ( ) const

Definition at line 239 of file dir.cpp.

240{
241 return fromFsPath(p->path);
242}

References fromFsPath(), and p.

Referenced by cleanDirPath(), Dir(), exists(), filePath(), isRelativePath(), mkdir(), DotGraph::prepareDotFile(), remove(), rmdir(), setCurrent(), and setPath().

◆ remove()

◆ rename()

bool Dir::rename ( const std::string & orgName,
const std::string & newName,
bool acceptsAbsPath = true ) const

Definition at line 326 of file dir.cpp.

327{
328 std::error_code ec;
329 std::string fn1 = filePath(orgName,acceptsAbsPath);
330 std::string fn2 = filePath(newName,acceptsAbsPath);
331 fs::rename(toFsPath(fn1),toFsPath(fn2),ec);
332 return !ec;
333}

References filePath(), and toFsPath().

Referenced by openOutputFile(), RTFGenerator::preProcessFileInplace(), resetPDFSize(), DotFilePatcher::run(), and DotRunner::run().

◆ rmdir()

bool Dir::rmdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 314 of file dir.cpp.

315{
316 return remove(path,acceptsAbsPath);
317}
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:319

References path(), and remove().

Referenced by clearSubDirs(), and CitationManager::generatePage().

◆ setCurrent()

bool Dir::setCurrent ( const std::string & path)
static

◆ setPath()

void Dir::setPath ( const std::string & path)

Definition at line 234 of file dir.cpp.

235{
236 p->path = toFsPath(path);
237}

References p, path(), and toFsPath().

Referenced by PerlModGenerator::createOutputDir(), Dir(), Htags::execute(), and parseInput().

Member Data Documentation

◆ p

std::unique_ptr<Private> Dir::p
private

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