diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-06-24 16:08:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-24 16:08:08 -0400 |
| commit | f1b41a71be938b8711ee0fff0130185f512d2336 (patch) | |
| tree | 29ad602a61968e1aacdf8424afc0c89defdb4330 /source/core | |
| parent | c12c0ad7fbb0272283f224493dbc28d9d60e7b91 (diff) | |
Handling of temporary files (#2299)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Work around windows issue with temporary file clash.
* Handle the temporary file path actually creates a file.
* Fix typo.
* Fix typo in linux for temporary file.
* Add unit test for io. Tests generateTemporary operation.
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-io.cpp | 7 | ||||
| -rw-r--r-- | source/core/slang-io.h | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index c11ba85e0..17cd60160 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -101,7 +101,8 @@ namespace Slang char* chars = tempFileName.prepareForAppend(count); // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea - // Generates a temporary file name. + // Generates a temporary file name. + // Will create a file with this name. DWORD ret = ::GetTempFileNameA(tempPath.getBuffer(), prefix.getBuffer(), 0, chars); if (ret == 0) @@ -111,6 +112,8 @@ namespace Slang tempFileName.appendInPlace(chars, ::strlen(chars)); } + SLANG_ASSERT(File::exists(tempFileName)); + outFileName = tempFileName; return SLANG_OK; } @@ -135,6 +138,8 @@ namespace Slang close(handle); outFileName = buffer.getBuffer(); + SLANG_ASSERT(File::exists(outFileName)); + return SLANG_OK; } #endif diff --git a/source/core/slang-io.h b/source/core/slang-io.h index 51b1d45e5..43812aaf9 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -27,6 +27,9 @@ namespace Slang static SlangResult makeExecutable(const String& fileName); + /// Creates a temporary file typically in some way based on the prefix + /// The file will be *created* with the outFileName, on success. + /// It's creation in necessary to lock that particular name. static SlangResult generateTemporary(const UnownedStringSlice& prefix, String& outFileName); }; |
