Directory: | cvmfs/ |
---|---|
File: | cvmfs/network/sink_path.cc |
Date: | 2025-06-22 02:36:02 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 11 | 18 | 61.1% |
Branches: | 7 | 28 | 25.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | #include "sink_path.h" | ||
6 | |||
7 | #include <cerrno> | ||
8 | #include <cstdio> | ||
9 | #include <string> | ||
10 | |||
11 | #include "util/posix.h" | ||
12 | |||
13 | |||
14 | namespace cvmfs { | ||
15 | |||
16 | 192 | PathSink::PathSink(const std::string &destination_path) | |
17 |
2/4✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 192 times.
✗ Branch 6 not taken.
|
192 | : Sink(true), path_(destination_path) { |
18 |
1/2✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
192 | file_ = fopen(destination_path.c_str(), "w"); |
19 |
2/4✓ Branch 1 taken 192 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 192 times.
✗ Branch 6 not taken.
|
192 | sink_ = new FileSink(file_, true); |
20 | 192 | } | |
21 | |||
22 | /** | ||
23 | * Purges all resources leaving the sink in an invalid state. | ||
24 | * More aggressive version of Reset(). | ||
25 | * For some sinks and depending on owner status it might do | ||
26 | * the same as Reset(). | ||
27 | * | ||
28 | * @returns Success = 0 | ||
29 | * Failure = -errno | ||
30 | */ | ||
31 | 48 | int PathSink::Purge() { | |
32 | 48 | const int ret = sink_->Purge(); | |
33 | 48 | const int ret2 = unlink(path_.c_str()); | |
34 | |||
35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (ret != 0) { |
36 | ✗ | return ret; | |
37 | } | ||
38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (ret2 != 0) { |
39 | ✗ | return ret2; | |
40 | } | ||
41 | 48 | return 0; | |
42 | } | ||
43 | |||
44 | /** | ||
45 | * Return a string representation describing the type of sink and its status | ||
46 | */ | ||
47 | ✗ | std::string PathSink::Describe() { | |
48 | ✗ | std::string result = "Path sink for "; | |
49 | ✗ | result += "path " + path_ + " and "; | |
50 | ✗ | result += IsValid() ? " valid file pointer" : " invalid file pointer"; | |
51 | ✗ | return result; | |
52 | } | ||
53 | |||
54 | } // namespace cvmfs | ||
55 |