3131
3232#include < algorithm>
3333#include < chrono>
34+ #include < filesystem>
3435#include < iostream>
3536#include < regex>
3637#include < stdexcept>
@@ -155,10 +156,10 @@ ensure_dotlnav()
155156 " formats/default" ,
156157 " formats/installed" ,
157158 " staging" ,
158- " stdin-captures" ,
159159 " crash" ,
160160 };
161161
162+ std::error_code ec;
162163 auto path = lnav::paths::dotlnav ();
163164
164165 for (const auto * sub_path : subdirs) {
@@ -179,7 +180,6 @@ ensure_dotlnav()
179180 auto crash_glob = path / " crash-*" ;
180181
181182 if (glob (crash_glob.c_str (), GLOB_NOCHECK, nullptr , gl.inout ()) == 0 ) {
182- std::error_code ec;
183183 for (size_t lpc = 0 ; lpc < gl->gl_pathc ; lpc++) {
184184 auto crash_file = std::filesystem::path (gl->gl_pathv [lpc]);
185185
@@ -202,9 +202,10 @@ ensure_dotlnav()
202202 }
203203 }
204204
205- {
205+ auto old_cap_path = path / " stdin-captures" ;
206+ if (std::filesystem::exists (old_cap_path, ec)) {
206207 static_root_mem<glob_t , globfree> gl;
207- auto cap_glob = path / " stdin-captures/ *" ;
208+ auto cap_glob = old_cap_path / " *" ;
208209
209210 if (glob (cap_glob.c_str (), GLOB_NOCHECK, nullptr , gl.inout ()) == 0 ) {
210211 auto old_time
@@ -227,6 +228,11 @@ ensure_dotlnav()
227228 log_perror (remove (gl->gl_pathv [lpc]));
228229 }
229230 }
231+
232+ if (std::filesystem::is_empty (old_cap_path, ec)) {
233+ log_info (" removing old stdin-captures directory" );
234+ std::filesystem::remove (old_cap_path, ec);
235+ }
230236 }
231237}
232238
0 commit comments