TempFilesDir() method call (TempFilesDir)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Code smell |
BSL |
Major |
Yes |
5 |
standard badpractice |
Description¶
When you use GetTemporaryFileName(), 1С:Enterprise retains control over these files and by default deletes them as soon as a working process (if a file is created on the server side) or client application (if a file is created on the client side) is restarted.
If a temporary file name is generated otherwise, and the application code fails (or is for any other reason unable) to delete a temporary file, it is not controlled by the platform and is saved in the file system for an indefinite time. Lost temporary files accumulated in the system can pose a serious problem, specifically for infobases with a great number of active users (for example, in the service mode).
Examples¶
Incorrect:
Catalog = TempFilesDir();
FileName = String(New UUID) + ".xml";
TempFile = Catalog + FileName;
Data.Write(TempFile);
Correct:
TempFile = GetTempFileName("xml");
Data.Write(TempFile);
To create a temporary directory, it is recommended to use the one obtained by the GetTempFileName method (with the exception of the web client).
Incorrect:
ArchFile = New ZipFileReader(FileName);
ArchCatalog = TempFilesDir()+"main_zip\";
CreateDirectory(ArchCatalog);
ArchFile.ExtractAll(ArchCatalog);
Correct:
ArchFile = New ZipFileReader(FileName);
ArchCatalog = GetTempFileName() + "\main_zip\";
CreateDirectory(ArchCatalog);
ArchFile.ExtractAll(ArchCatalog);
Sources¶
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:TempFilesDir-off
// BSLLS:TempFilesDir-on
Parameter for config¶
"TempFilesDir": false