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