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