• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 17589970077-2502

09 Sep 2025 05:00PM UTC coverage: 65.196% (-5.0%) from 70.225%
17589970077-2502

push

github

tstack
[format] add fields for source file/line

Knowing the source file/line context in a log
message can help find log messages when using
log2src.

56 of 70 new or added lines in 2 files covered. (80.0%)

13954 existing lines in 210 files now uncovered.

45516 of 69814 relevant lines covered (65.2%)

404154.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/src/base/paths.cc
1
/**
2
 * Copyright (c) 2021, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include <filesystem>
31

32
#ifdef __CYGWIN__
33
#include <algorithm>
34
#endif
35

36
#include <unistd.h>
37

38
#include "config.h"
39
#include "fmt/format.h"
40
#include "lnav_log.hh"
41
#include "opt_util.hh"
42
#include "paths.hh"
43

44
namespace lnav::paths {
45

46
#ifdef __CYGWIN__
47
std::string
48
windows_to_unix_file_path(const std::string& input)
49
{
50
    static const auto CYGDRIVE = std::filesystem::path("/cygdrive");
51

52
    std::string file_path;
53
    file_path.assign(input);
54

55
    // Replace the slashes
56
    std::replace(file_path.begin(),
57
                 file_path.end(),
58
                 WINDOWS_FILE_PATH_SEPARATOR,
59
                 UNIX_FILE_PATH_SEPARATOR);
60

61
    // Convert the drive letter to lowercase
62
    std::transform(
63
        file_path.begin(),
64
        file_path.begin() + 1,
65
        file_path.begin(),
66
        [](unsigned char character) { return std::tolower(character); });
67

68
    // Remove the colon
69
    const auto drive_letter = file_path.substr(0, 1);
70
    const auto remaining_path = file_path.substr(2, file_path.size() - 2);
71
    file_path = drive_letter + remaining_path;
72

73
    return (CYGDRIVE / file_path).string();
74
}
75
#endif
76

77
std::filesystem::path
78
dotlnav()
14,828✔
79
{
80
    auto home_env = std::string(getenv_opt("HOME").value_or(""));
14,828✔
81
    const auto* xdg_config_home = getenv("XDG_CONFIG_HOME");
14,828✔
82

83
#ifdef __CYGWIN__
84
    const auto* app_data = getenv("APPDATA");
85
    if (app_data != nullptr) {
86
        auto app_data_path = std::filesystem::path(windows_to_unix_file_path(app_data));
87

88
        if (std::filesystem::is_directory(app_data_path)) {
89
            return app_data_path / "lnav";
90
        }
91
    }
92
#endif
93

94
    if (!home_env.empty()) {
14,828✔
95
        auto home_path = std::filesystem::path(home_env);
14,828✔
96

97
        if (std::filesystem::is_directory(home_path)) {
14,828✔
98
            auto home_lnav = home_path / ".lnav";
14,828✔
99

100
            if (std::filesystem::is_directory(home_lnav)) {
14,828✔
101
                return home_lnav;
13,139✔
102
            }
103

104
            if (xdg_config_home != nullptr) {
1,689✔
105
                auto xdg_path = std::filesystem::path(xdg_config_home);
1,017✔
106

107
                if (std::filesystem::is_directory(xdg_path)) {
1,017✔
108
                    return xdg_path / "lnav";
1,017✔
109
                }
110
            }
1,017✔
111

112
            auto home_config = home_path / ".config";
672✔
113

114
            if (std::filesystem::is_directory(home_config)) {
672✔
115
                return home_config / "lnav";
212✔
116
            }
117

118
            return home_lnav;
460✔
119
        }
14,828✔
120
    }
14,828✔
121

UNCOV
122
    std::error_code ec;
×
UNCOV
123
    auto retval = std::filesystem::current_path(ec);
×
UNCOV
124
    if (ec) {
×
UNCOV
125
        retval = std::filesystem::temp_directory_path();
×
126
    }
127

UNCOV
128
    return retval;
×
129
}
14,828✔
130

131
std::filesystem::path
132
workdir()
3,511✔
133
{
134
    auto subdir_name = fmt::format(FMT_STRING("lnav-user-{}-work"), getuid());
10,533✔
135
    auto tmp_path = std::filesystem::temp_directory_path();
3,511✔
136

137
    return tmp_path / std::filesystem::path(subdir_name);
7,022✔
138
}
3,511✔
139

140
}  // namespace lnav::paths
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc