Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFileLock.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmFileLock.h"
4
5
#include <cassert>
6
#include <utility>
7
8
#include "cmFileLockResult.h"
9
10
// Common implementation
11
12
cmFileLock::cmFileLock(cmFileLock&& other) noexcept
13
0
{
14
0
  this->File = other.File;
15
0
  other.File = (decltype(other.File))-1;
16
0
  this->Filename = std::move(other.Filename);
17
#if defined(_WIN32)
18
  this->Overlapped = std::move(other.Overlapped);
19
#endif
20
0
}
21
22
cmFileLock::~cmFileLock()
23
134
{
24
134
  if (!this->Filename.empty()) {
25
0
    cmFileLockResult const result = this->Release();
26
0
    static_cast<void>(result);
27
0
    assert(result.IsOk());
28
0
  }
29
134
}
30
31
cmFileLock& cmFileLock::operator=(cmFileLock&& other) noexcept
32
0
{
33
0
  this->File = other.File;
34
0
  other.File = (decltype(other.File))-1;
35
0
  this->Filename = std::move(other.Filename);
36
#if defined(_WIN32)
37
  this->Overlapped = std::move(other.Overlapped);
38
#endif
39
40
0
  return *this;
41
0
}
42
43
cmFileLockResult cmFileLock::Lock(std::string const& filename,
44
                                  unsigned long timeout)
45
134
{
46
134
  if (filename.empty()) {
47
    // Error is internal since all the directories and file must be created
48
    // before actual lock called.
49
0
    return cmFileLockResult::MakeInternal();
50
0
  }
51
52
134
  if (!this->Filename.empty()) {
53
    // Error is internal since double-lock must be checked in class
54
    // cmFileLockPool by the cmFileLock::IsLocked method.
55
0
    return cmFileLockResult::MakeInternal();
56
0
  }
57
58
134
  this->Filename = filename;
59
134
  cmFileLockResult result = this->OpenFile();
60
134
  if (result.IsOk()) {
61
69
    if (timeout == static_cast<unsigned long>(-1)) {
62
0
      result = this->LockWithoutTimeout();
63
69
    } else {
64
69
      result = this->LockWithTimeout(timeout);
65
69
    }
66
69
  }
67
68
134
  if (!result.IsOk()) {
69
65
    this->Filename.clear();
70
65
  }
71
72
134
  return result;
73
134
}
74
75
bool cmFileLock::IsLocked(std::string const& filename) const
76
0
{
77
0
  return filename == this->Filename;
78
0
}
79
80
#if defined(_WIN32)
81
// NOLINTNEXTLINE(bugprone-suspicious-include)
82
#  include "cmFileLockWin32.cxx"
83
#else
84
// NOLINTNEXTLINE(bugprone-suspicious-include)
85
#  include "cmFileLockUnix.cxx"
86
#endif