Skip to content

BSL250 - TempFilesDir() method call

Summary

TempFilesDir() method call

Identifiers

Field Value
Rule code BSL250
Compatible alias TempFilesDir
Severity WARNING
Without configuration Yes
BSLLS JSON, ON mode without overrides Yes
Registry flag implemented Yes
Tags standard, badpractice

The implemented flag describes the registry; it does not certify verified BSLLS parity.

Behavior

  • The public identifier BSL250 and alias TempFilesDir 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 = ["BSL250"]
ignore = ["TempFilesDir"]

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: BSL250
  • bsl-disable:
Value = "example";  // bsl-disable: BSL250
  • compatible BSLLS form:
Value = "example";  // BSLLS:TempFilesDir-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: BSL250
// code without this diagnostic
// noqa-enable: BSL250

// bsl-disable: BSL250
// code without this diagnostic
// bsl-enable: BSL250

// BSLLS:TempFilesDir-off
// code without this diagnostic
// BSLLS:TempFilesDir-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

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