MCPcopy Create free account
hub / github.com/apache/cloudberry / PathNameCreateTemporaryFile

Function PathNameCreateTemporaryFile

src/backend/storage/file/fd.c:1827–1857  ·  view source on GitHub ↗

* Create a new file. The directory containing it must already exist. Files * created this way are subject to temp_file_limit and are automatically * closed at end of transaction, but are not automatically deleted on close * because they are intended to be shared between cooperating backends. * * If the file is inside the top-level temporary directory, its name should * begin with PG_TEMP_F

Source from the content-addressed store, hash-verified

1825 * the prefix isn't needed.
1826 */
1827File
1828PathNameCreateTemporaryFile(const char *path, bool error_on_failure)
1829{
1830 File file;
1831
1832 ResourceOwnerEnlargeFiles(CurrentResourceOwner);
1833
1834 /*
1835 * Open the file. Note: we don't use O_EXCL, in case there is an orphaned
1836 * temp file that can be reused.
1837 */
1838 file = PathNameOpenFile(path, O_RDWR | O_CREAT | O_TRUNC | PG_BINARY);
1839 if (file <= 0)
1840 {
1841 if (error_on_failure)
1842 ereport(ERROR,
1843 (errcode_for_file_access(),
1844 errmsg("could not create temporary file \"%s\": %m",
1845 path)));
1846 else
1847 return file;
1848 }
1849
1850 /* Mark it for temp_file_limit accounting. */
1851 VfdCache[file].fdstate |= FD_TEMP_FILE_LIMIT;
1852
1853 /* Register it for automatic close. */
1854 RegisterTemporaryFile(file);
1855
1856 return file;
1857}
1858
1859/*
1860 * Open a file that was created with PathNameCreateTemporaryFile, possibly in

Callers 1

SharedFileSetCreateFunction · 0.85

Calls 5

PathNameOpenFileFunction · 0.85
RegisterTemporaryFileFunction · 0.85
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected