Skip to content

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 BSL218 and alias MissingTemporaryFileDeletion are 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.

[tool.onec-hbk-bsl]
select = ["BSL218"]
ignore = ["MissingTemporaryFileDeletion"]

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:
Value = "example";  // noqa: BSL218
  • bsl-disable:
Value = "example";  // bsl-disable: BSL218
  • compatible BSLLS form:
Value = "example";  // BSLLS:MissingTemporaryFileDeletion-off

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:

TempFileName = GetTempFileName("xml");
Data.Write(TempFileName);
// Not delete temporary file

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 MyFileDeletion in the GlobalServer module in the parameter is specified as MyFileDeletion
  • Method MyFileDeletion in the common module FilesClientServer in the parameter is specified as FilesClientServer.MyFileDelete
  • Method MyFileOperations in the module of the catalog manager FileOperations in the parameter is specified as Catalogs.FileOperations.MyFileOperations

and so on.

Sources