LLVM 23.0.0git
llvm::cas::ondisk::UniqueTempFile Class Reference

Helper RAII class for copying a file to a unique file path. More...

#include "CAS/OnDiskCommon.h"

Public Member Functions

 UniqueTempFile ()=default
 ~UniqueTempFile ()
Expected< StringRefcreateAndCopyFrom (StringRef ParentPath, StringRef CopyFromPath)
 Create a new unique file path under ParentPath and copy the contents of CopyFromPath into it.
Error renameTo (StringRef RenameToPath)
 Rename the new unique file to RenameToPath.

Detailed Description

Helper RAII class for copying a file to a unique file path.

At destruction time it will delete any new temporary files created.

Definition at line 75 of file OnDiskCommon.h.

Constructor & Destructor Documentation

◆ UniqueTempFile()

llvm::cas::ondisk::UniqueTempFile::UniqueTempFile ( )
default

◆ ~UniqueTempFile()

cas::ondisk::UniqueTempFile::~UniqueTempFile ( )

Definition at line 249 of file OnDiskCommon.cpp.

References llvm::sys::fs::remove().

Member Function Documentation

◆ createAndCopyFrom()

Expected< StringRef > cas::ondisk::UniqueTempFile::createAndCopyFrom ( StringRef ParentPath,
StringRef CopyFromPath )

Create a new unique file path under ParentPath and copy the contents of CopyFromPath into it.

It will use file cloning when applicable.

Returns
the new unique file path.

Definition at line 220 of file OnDiskCommon.cpp.

References llvm::sys::path::append(), llvm::sys::fs::copy_file(), llvm::createFileError(), and llvm::sys::fs::createUniqueFile().

◆ renameTo()

Error cas::ondisk::UniqueTempFile::renameTo ( StringRef RenameToPath)

Rename the new unique file to RenameToPath.

This is useful to indicate that the unique file doesn't need to be cleared at destruction time.

Definition at line 242 of file OnDiskCommon.cpp.

References llvm::createFileError(), llvm::sys::fs::rename(), and llvm::Error::success().


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