BSL218 — Missing temporary file deletion after using¶
Summary¶
Missing temporary file deletion after using
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL218 |
| Compatible alias | MissingTemporaryFileDeletion |
| Severity | WARNING |
| Enabled by default | Yes |
| Implemented | Yes |
| Tags | resource-management |
Behavior¶
- The public identifier
BSL218and aliasMissingTemporaryFileDeletionare stable. - The rule reports the cases documented on this page.
- Suppressions and project configuration are applied before publication.
- The rule requires neither an external analyzer nor network access.
Configuration and suppression¶
BSL### is the primary stable identifier. The compatible alias is accepted
in select, ignore, and compatible block suppression comments.
All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:
noqa:
bsl-disable:
- compatible
BSLLSform:
When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:
// noqa: BSL218
// code without this diagnostic
// noqa-enable: BSL218
// bsl-disable: BSL218
// code without this diagnostic
// bsl-enable: BSL218
// BSLLS:MissingTemporaryFileDeletion-off
// code without this diagnostic
// BSLLS:MissingTemporaryFileDeletion-on
To disable the rule until the end of the file, omit the closing
noqa-enable, bsl-enable, or BSLLS:…-on marker.
Opening and closing markers must belong to the same family.
Description¶
After you finished working with temporary file or folder, you need to delete it yourself. You should not rely on automatic deletion of files and folders before platform start. This can cause temp folder free space shortage.
Examples¶
Incorrect:
Correct:
TempFileName = GetTempFileName("xml");
Data.Write(TempFileName);
// Work with file
...
// Delete temporary file
Try
DeleteFiles(TempFileName);
Catch
WriteLogEvent(НСтр("ru = 'My subsystem.Action'"), EventLogLevel.Error, , , DetailErrorDescription(ErrorInfo()));
EndTry;
Nuances¶
Diagnostics determines the correctness of working with temporary files by the presence of methods for deleting or moving.
If the applied solution uses its own method of removing/moving over the platform one, then it is worth specifying it in the diagnostic parameter, adding it after |. Diagnostics understands both global methods and those located in common modules or manager modules.
The following is an examples of a settings
- The global method
MyFileDeletionin theGlobalServermodule in the parameter is specified asMyFileDeletion - Method
MyFileDeletionin the common moduleFilesClientServerin the parameter is specified asFilesClientServer.MyFileDelete - Method
MyFileOperationsin the module of the catalog managerFileOperationsin the parameter is specified asCatalogs.FileOperations.MyFileOperations
and so on.