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)
Diroperator= (const Dir &d)
 Dir (Dir &&d)
Diroperator= (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< Privatep

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 190 of file dir.cpp.

190 : p(std::make_unique<Private>())
191{
192 std::error_code ec;
193 p->path = fs::current_path(ec);
194}
std::unique_ptr< Private > p
Definition dir.h:108

References p.

Referenced by cleanupInlineGraphs(), copyFile(), Dir(), Dir(), DocParser::findAndCopyImage(), getMscImageMapFromFile(), openDbConnection(), operator=(), operator=(), runPlantumlContent(), writeDiaGraphFromFile(), ClassDiagram::writeFigure(), DotGraph::writeGraph(), and writeMscGraphFromFile().

◆ Dir() [2/4]

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

Definition at line 221 of file dir.cpp.

221 : p(std::make_unique<Private>())
222{
223 setPath(path);
224}
void setPath(const std::string &path)
Definition dir.cpp:230
std::string path() const
Definition dir.cpp:235

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

◆ Dir() [3/4]

Dir::Dir ( const Dir & d)

Definition at line 196 of file dir.cpp.

196 : p(std::make_unique<Private>())
197{
198 p->path = d.p->path;
199}

References Dir(), and p.

◆ Dir() [4/4]

Dir::Dir ( Dir && d)

Definition at line 210 of file dir.cpp.

210 : p(std::make_unique<Private>())
211{
212 std::exchange(p->path,d.p->path);
213}

References Dir(), and p.

◆ ~Dir()

Dir::~Dir ( )

Definition at line 226 of file dir.cpp.

227{
228}

Member Function Documentation

◆ absPath()

std::string Dir::absPath ( ) const

Definition at line 365 of file dir.cpp.

366{
367 std::error_code ec;
368 std::string result = fs::absolute(p->path,ec).string();
369 correctPath(result);
370 return result;
371}
static void correctPath(std::string &s)
Definition dir.cpp:245

References correctPath(), 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 358 of file dir.cpp.

359{
360 std::string result = fs::path(path).lexically_normal().string();
361 correctPath(result);
362 return result;
363}

References correctPath(), and path().

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 331 of file dir.cpp.

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

References filePath().

◆ currentDirPath()

std::string Dir::currentDirPath ( )
static

◆ empty()

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

Definition at line 264 of file dir.cpp.

265{
266 fs::path pth = path();
267 pth /= subdir;
268 return fs::is_empty(pth);
269}

References path().

Referenced by clearSubDirs().

◆ exists() [1/2]

◆ exists() [2/2]

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

Definition at line 250 of file dir.cpp.

251{
252 std::string result = filePath(path,acceptsAbsPath);
253 std::error_code ec;
254 bool exist = fs::exists(fs::path(result),ec);
255 return !ec && exist;
256}

References filePath(), and path().

◆ filePath()

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

Definition at line 281 of file dir.cpp.

282{
283 std::string result;
284 if (acceptsAbsPath && !isRelativePath(path))
285 {
286 result = path;
287 }
288 else
289 {
290 result = (p->path / path).string();
291 }
292 correctPath(result);
293 return result;
294}
static bool isRelativePath(const std::string &path)
Definition dir.cpp:276

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

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

◆ isRelative()

bool Dir::isRelative ( ) const

Definition at line 271 of file dir.cpp.

272{
273 return isRelativePath(p->path.string());
274}

References isRelativePath(), and p.

◆ isRelativePath()

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

Definition at line 276 of file dir.cpp.

277{
278 return fs::path(path).is_relative();
279}

References path().

Referenced by filePath(), and isRelative().

◆ iterator()

DirIterator Dir::iterator ( ) const

Definition at line 240 of file dir.cpp.

241{
242 return DirIterator(p->path.string());
243}
DirIterator()
Definition dir.cpp:97

References DirIterator::DirIterator(), and p.

Referenced by readDir().

◆ mkdir()

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

Definition at line 296 of file dir.cpp.

297{
298 std::error_code ec;
299 std::string result = filePath(path,acceptsAbsPath);
300 if (exists(path,acceptsAbsPath))
301 {
302 return true;
303 }
304 else
305 {
306 return fs::create_directory(result,ec);
307 }
308}
bool exists() const
Definition dir.cpp:258

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

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 201 of file dir.cpp.

202{
203 if (&d!=this)
204 {
205 p->path = d.p->path;
206 }
207 return *this;
208}

References Dir(), and p.

◆ operator=() [2/2]

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

Definition at line 215 of file dir.cpp.

216{
217 std::exchange(p->path,d.p->path);
218 return *this;
219}

References Dir(), and p.

◆ path()

std::string Dir::path ( ) const

Definition at line 235 of file dir.cpp.

236{
237 return p->path.string();
238}

References p.

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

◆ remove()

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

Definition at line 315 of file dir.cpp.

316{
317 std::error_code ec;
318 std::string result = filePath(path,acceptsAbsPath);
319 return fs::remove(result,ec);
320}

References filePath(), and path().

Referenced by determineInkscapeVersion(), exitDoxygen(), FormulaManager::generateImages(), generateOutput(), CitationManager::generatePage(), openOutputFile(), RTFGenerator::preProcessFileInplace(), resetPDFSize(), rmdir(), DotFilePatcher::run(), stopDoxygen(), and writeDotImageMapFromFile().

◆ rename()

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

Definition at line 322 of file dir.cpp.

323{
324 std::error_code ec;
325 std::string fn1 = filePath(orgName,acceptsAbsPath);
326 std::string fn2 = filePath(newName,acceptsAbsPath);
327 fs::rename(fn1,fn2,ec);
328 return !ec;
329}

References filePath().

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 310 of file dir.cpp.

311{
312 return remove(path,acceptsAbsPath);
313}
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:315

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 230 of file dir.cpp.

231{
232 p->path = path;
233}

References p, and path().

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: