Skip to content

Commit 137c742

Browse files
committed
Revert "Replace file_util.{h,cpp} by std::filesystem"
This reverts commit e8cbe9d.
1 parent 5d1b0e8 commit 137c742

20 files changed

+526
-114
lines changed

jbmc/src/java_bytecode/java_class_loader_base.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Author: Daniel Kroening, [email protected]
88

99
#include "java_class_loader_base.h"
1010

11-
#include <util/message.h>
12-
#include <util/prefix.h>
13-
#include <util/suffix.h>
14-
1511
#include "jar_file.h"
1612
#include "java_bytecode_parse_tree.h"
1713
#include "java_bytecode_parser.h"
1814

19-
#include <filesystem>
15+
#include <util/file_util.h>
16+
#include <util/message.h>
17+
#include <util/prefix.h>
18+
#include <util/suffix.h>
19+
2020
#include <fstream>
2121

2222
void java_class_loader_baset::add_classpath_entry(
@@ -40,7 +40,7 @@ void java_class_loader_baset::add_classpath_entry(
4040
}
4141
else
4242
{
43-
if(std::filesystem::is_directory(path))
43+
if(is_directory(path))
4444
{
4545
classpath_entries.push_back(
4646
classpath_entryt(classpath_entryt::DIRECTORY, path));
@@ -197,8 +197,7 @@ java_class_loader_baset::get_class_from_directory(
197197
{
198198
// Look in the given directory
199199
const std::string class_file = class_name_to_os_file(class_name);
200-
const std::string full_path =
201-
std::filesystem::path(path).append(class_file).string();
200+
const std::string full_path = concat_dir_file(path, class_file);
202201

203202
if(std::ifstream(full_path))
204203
{

jbmc/unit/java-testing-utils/load_java_class.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ Author: Diffblue Ltd.
88

99
#include "load_java_class.h"
1010

11+
#include <iostream>
12+
#include <testing-utils/free_form_cmdline.h>
13+
#include <testing-utils/message.h>
14+
#include <testing-utils/use_catch.h>
15+
1116
#include <util/config.h>
1217
#include <util/options.h>
1318
#include <util/suffix.h>
1419

15-
#include <java_bytecode/java_bytecode_language.h>
1620
#include <java_bytecode/lazy_goto_model.h>
17-
#include <testing-utils/free_form_cmdline.h>
18-
#include <testing-utils/message.h>
19-
#include <testing-utils/use_catch.h>
2021

21-
#include <filesystem>
22-
#include <iostream>
22+
#include <java_bytecode/java_bytecode_language.h>
23+
#include <util/file_util.h>
2324

2425
/// Go through the process of loading, type-checking and finalising loading a
2526
/// specific class file to build the symbol table. The functions are converted
@@ -148,7 +149,7 @@ goto_modelt load_goto_model_from_java_class(
148149
// Log the working directory to help people identify the common error
149150
// of wrong working directory (should be the `unit` directory when running
150151
// the unit tests).
151-
std::string path = std::filesystem::current_path().string();
152+
std::string path = get_current_working_directory();
152153
INFO("Working directory: " << path);
153154

154155
// if this fails it indicates the class was not loaded

src/crangler/c_wrangler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <util/cprover_prefix.h>
1919
#include <util/exception_utils.h>
20+
#include <util/file_util.h>
2021
#include <util/json.h>
2122
#include <util/optional.h>
2223
#include <util/prefix.h>

src/goto-analyzer/unreachable_instructions.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Date: April 2016
1313

1414
#include "unreachable_instructions.h"
1515

16+
#include <util/file_util.h>
1617
#include <util/json_irep.h>
1718
#include <util/options.h>
1819
#include <util/xml.h>
@@ -22,8 +23,6 @@ Date: April 2016
2223
#include <analyses/ai.h>
2324
#include <analyses/cfg_dominators.h>
2425

25-
#include <filesystem>
26-
2726
typedef std::map<unsigned, goto_programt::const_targett> dead_mapt;
2827

2928
static void unreachable_instructions(
@@ -107,10 +106,9 @@ file_name_string_opt(const source_locationt &source_location)
107106
if(source_location.get_file().empty())
108107
return {};
109108

110-
return std::filesystem::path(
111-
id2string(source_location.get_working_directory()))
112-
.append(id2string(source_location.get_file()))
113-
.string();
109+
return concat_dir_file(
110+
id2string(source_location.get_working_directory()),
111+
id2string(source_location.get_file()));
114112
}
115113

116114
static void add_to_json(

src/goto-cc/as_mode.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ Author: Michael Tautschnig
1919
#include <sysexits.h>
2020
#endif
2121

22+
#include <fstream>
23+
#include <iostream>
24+
2225
#include <util/cmdline.h>
2326
#include <util/config.h>
27+
#include <util/file_util.h>
2428
#include <util/get_base_name.h>
2529
#include <util/run.h>
2630
#include <util/tempdir.h>
@@ -30,10 +34,6 @@ Author: Michael Tautschnig
3034
#include "goto_cc_cmdline.h"
3135
#include "hybrid_binary.h"
3236

33-
#include <filesystem>
34-
#include <fstream>
35-
#include <iostream>
36-
3737
static std::string assembler_name(
3838
const cmdlinet &cmdline,
3939
const std::string &base_name)
@@ -303,9 +303,9 @@ int as_modet::as_hybrid_binary(const compilet &compiler)
303303
std::string saved = output_file + ".goto-cc-saved";
304304
try
305305
{
306-
std::filesystem::rename(output_file, saved);
306+
file_rename(output_file, saved);
307307
}
308-
catch(const std::filesystem::filesystem_error &e)
308+
catch(const cprover_exception_baset &e)
309309
{
310310
log.error() << "Rename failed: " << e.what() << messaget::eom;
311311
return 1;

src/goto-cc/compile.cpp

+16-28
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ Date: June 2006
1313

1414
#include "compile.h"
1515

16+
#include <cstring>
17+
#include <fstream>
18+
#include <iostream>
19+
1620
#include <util/cmdline.h>
1721
#include <util/config.h>
22+
#include <util/file_util.h>
1823
#include <util/get_base_name.h>
1924
#include <util/prefix.h>
2025
#include <util/run.h>
@@ -23,11 +28,6 @@ Date: June 2006
2328
#include <util/tempfile.h>
2429
#include <util/version.h>
2530

26-
#include <cstring>
27-
#include <filesystem>
28-
#include <fstream>
29-
#include <iostream>
30-
3131
#ifdef _MSC_VER
3232
# include <util/unicode.h>
3333
#endif
@@ -222,14 +222,11 @@ bool compilet::add_files_from_archive(
222222
tstr = get_temporary_directory("goto-cc.XXXXXX");
223223

224224
tmp_dirs.push_back(tstr);
225-
std::filesystem::current_path(tmp_dirs.back());
225+
set_current_path(tmp_dirs.back());
226226

227227
// unpack now
228-
int ret = run(
229-
"ar",
230-
{"ar",
231-
"x",
232-
std::filesystem::path(working_directory).append(file_name).string()});
228+
int ret =
229+
run("ar", {"ar", "x", concat_dir_file(working_directory, file_name)});
233230
if(ret != 0)
234231
{
235232
log.error() << "Failed to extract archive " << file_name << messaget::eom;
@@ -241,9 +238,7 @@ bool compilet::add_files_from_archive(
241238
temporary_filet tmp_file_out("", "");
242239
int ret = run(
243240
"ar",
244-
{"ar",
245-
"t",
246-
std::filesystem::path(working_directory).append(file_name).string()},
241+
{"ar", "t", concat_dir_file(working_directory, file_name)},
247242
"",
248243
tmp_file_out(),
249244
"");
@@ -258,7 +253,7 @@ bool compilet::add_files_from_archive(
258253

259254
while(!in.fail() && std::getline(in, line))
260255
{
261-
std::string t = std::filesystem::path(tstr).append(line).string();
256+
std::string t = concat_dir_file(tstr, line);
262257

263258
if(is_goto_binary(t, log.get_message_handler()))
264259
object_files.push_back(t);
@@ -268,7 +263,7 @@ bool compilet::add_files_from_archive(
268263
}
269264

270265
if(!thin_archive)
271-
std::filesystem::current_path(working_directory);
266+
set_current_path(working_directory);
272267

273268
return false;
274269
}
@@ -282,18 +277,15 @@ bool compilet::find_library(const std::string &name)
282277

283278
for(const auto &library_path : library_paths)
284279
{
285-
library_file_name =
286-
std::filesystem::path(library_path).append("lib" + name + ".a").string();
280+
library_file_name = concat_dir_file(library_path, "lib" + name + ".a");
287281

288282
std::ifstream in(library_file_name);
289283

290284
if(in.is_open())
291285
return !add_input_file(library_file_name);
292286
else
293287
{
294-
library_file_name = std::filesystem::path(library_path)
295-
.append("lib" + name + ".so")
296-
.string();
288+
library_file_name = concat_dir_file(library_path, "lib" + name + ".so");
297289

298290
switch(detect_file_type(library_file_name, log.get_message_handler()))
299291
{
@@ -422,11 +414,7 @@ optionalt<symbol_tablet> compilet::compile()
422414
get_base_name(file_name, true) + "." + object_file_extension;
423415

424416
if(!output_directory_object.empty())
425-
{
426-
cfn = std::filesystem::path(output_directory_object)
427-
.append(file_name_with_obj_ext)
428-
.string();
429-
}
417+
cfn = concat_dir_file(output_directory_object, file_name_with_obj_ext);
430418
else
431419
cfn = file_name_with_obj_ext;
432420
}
@@ -669,7 +657,7 @@ compilet::compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
669657
mode=COMPILE_LINK_EXECUTABLE;
670658
echo_file_name=false;
671659
wrote_object=false;
672-
working_directory = std::filesystem::current_path().string();
660+
working_directory=get_current_working_directory();
673661

674662
if(cmdline.isset("export-function-local-symbols"))
675663
{
@@ -686,7 +674,7 @@ compilet::~compilet()
686674
// clean up temp dirs
687675

688676
for(const auto &dir : tmp_dirs)
689-
std::filesystem::remove_all(dir);
677+
delete_directory(dir);
690678
}
691679

692680
std::size_t compilet::function_body_count(const goto_functionst &functions)

src/goto-cc/gcc_mode.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ Author: CM Wintersteiger, 2006
1919
#include <sysexits.h>
2020
#endif
2121

22+
#include <iostream>
23+
#include <fstream>
24+
#include <numeric>
25+
2226
#include <util/cmdline.h>
2327
#include <util/config.h>
28+
#include <util/file_util.h>
2429
#include <util/get_base_name.h>
2530
#include <util/invariant.h>
2631
#include <util/prefix.h>
@@ -34,11 +39,6 @@ Author: CM Wintersteiger, 2006
3439
#include "hybrid_binary.h"
3540
#include "linker_script_merge.h"
3641

37-
#include <filesystem>
38-
#include <fstream>
39-
#include <iostream>
40-
#include <numeric>
41-
4242
static std::string compiler_name(
4343
const cmdlinet &cmdline,
4444
const std::string &base_name)
@@ -945,9 +945,9 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
945945

946946
try
947947
{
948-
std::filesystem::rename(*it, bin_name);
948+
file_rename(*it, bin_name);
949949
}
950-
catch(const std::filesystem::filesystem_error &e)
950+
catch(const cprover_exception_baset &e)
951951
{
952952
log.error() << "Rename failed: " << e.what() << messaget::eom;
953953
return 1;

src/goto-cc/hybrid_binary.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Author: Michael Tautschnig, 2018
1111

1212
#include "hybrid_binary.h"
1313

14+
#include <util/file_util.h>
1415
#include <util/message.h>
1516
#include <util/run.h>
1617
#include <util/suffix.h>
1718

1819
#include <cstring>
19-
#include <filesystem>
2020

2121
#if defined(__APPLE__)
2222
# include <sys/stat.h>
@@ -80,7 +80,7 @@ int hybrid_binary(
8080
}
8181

8282
// delete the goto binary
83-
bool remove_result = std::filesystem::remove(goto_binary_file);
83+
bool remove_result = file_remove(goto_binary_file);
8484
if(!remove_result)
8585
{
8686
message.error() << "Remove failed: " << std::strerror(errno)
@@ -140,7 +140,7 @@ int hybrid_binary(
140140
}
141141

142142
// delete the goto binary
143-
bool remove_result = std::filesystem::remove(goto_binary_file);
143+
bool remove_result = file_remove(goto_binary_file);
144144
if(!remove_result)
145145
{
146146
message.error() << "Remove failed: " << std::strerror(errno)

src/goto-cc/ld_mode.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ Author: CM Wintersteiger, 2006
1919
#include <sysexits.h>
2020
#endif
2121

22+
#include <cstring>
23+
#include <fstream>
24+
#include <iostream>
25+
2226
#include <util/cmdline.h>
2327
#include <util/config.h>
28+
#include <util/file_util.h>
2429
#include <util/invariant.h>
2530
#include <util/run.h>
2631

@@ -29,11 +34,6 @@ Author: CM Wintersteiger, 2006
2934
#include "hybrid_binary.h"
3035
#include "linker_script_merge.h"
3136

32-
#include <cstring>
33-
#include <filesystem>
34-
#include <fstream>
35-
#include <iostream>
36-
3737
static std::string
3838
linker_name(const cmdlinet &cmdline, const std::string &base_name)
3939
{
@@ -181,9 +181,9 @@ int ld_modet::ld_hybrid_binary(
181181

182182
try
183183
{
184-
std::filesystem::rename(output_file, goto_binary);
184+
file_rename(output_file, goto_binary);
185185
}
186-
catch(const std::filesystem::filesystem_error &e)
186+
catch(const cprover_exception_baset &e)
187187
{
188188
log.error() << "Rename failed: " << e.what() << messaget::eom;
189189
return 1;

0 commit comments

Comments
 (0)