mirror of
https://github.com/YosysHQ/yosys
synced 2025-05-14 11:14:44 +00:00
Merge pull request #5110 from YosysHQ/emil/gzip-reject-directory
gzip: reject uncompressing directory
This commit is contained in:
commit
c4af97c1c4
5 changed files with 36 additions and 25 deletions
|
@ -102,6 +102,8 @@ gzip_istream::ibuf::~ibuf() {
|
|||
// returns the original ifstream, rewound to the start.
|
||||
// Never returns nullptr or failed state istream*
|
||||
std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) {
|
||||
if (!check_file_exists(filename))
|
||||
log_cmd_error("File `%s' not found or is a directory\n", filename.c_str());
|
||||
std::ifstream* f = new std::ifstream();
|
||||
f->open(filename, mode);
|
||||
if (f->fail())
|
||||
|
|
15
kernel/io.cc
15
kernel/io.cc
|
@ -247,7 +247,7 @@ std::string make_temp_dir(std::string template_str)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool check_directory_exists(const std::string& dirname)
|
||||
bool check_is_directory(const std::string& dirname)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
struct _stat info;
|
||||
|
@ -267,17 +267,26 @@ bool check_directory_exists(const std::string& dirname)
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool check_file_exists(std::string filename, bool)
|
||||
bool check_accessible(const std::string& filename, bool)
|
||||
{
|
||||
return _access(filename.c_str(), 0) == 0;
|
||||
}
|
||||
#else
|
||||
bool check_file_exists(std::string filename, bool is_exec)
|
||||
bool check_accessible(const std::string& filename, bool is_exec)
|
||||
{
|
||||
return access(filename.c_str(), is_exec ? X_OK : F_OK) == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool check_file_exists(const std::string& filename, bool is_exec)
|
||||
{
|
||||
return check_accessible(filename, is_exec) && !check_is_directory(filename);
|
||||
}
|
||||
bool check_directory_exists(const std::string& filename, bool is_exec)
|
||||
{
|
||||
return check_accessible(filename, is_exec) && check_is_directory(filename);
|
||||
}
|
||||
|
||||
bool is_absolute_path(std::string filename)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
17
kernel/io.h
17
kernel/io.h
|
@ -64,6 +64,23 @@ inline std::string stringf(const char *fmt, ...)
|
|||
return string;
|
||||
}
|
||||
|
||||
int readsome(std::istream &f, char *s, int n);
|
||||
std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
|
||||
std::vector<std::string> split_tokens(const std::string &text, const char *sep = " \t\r\n");
|
||||
bool patmatch(const char *pattern, const char *string);
|
||||
#if !defined(YOSYS_DISABLE_SPAWN)
|
||||
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
|
||||
#endif
|
||||
std::string get_base_tmpdir();
|
||||
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||
bool check_file_exists(const std::string& filename, bool is_exec = false);
|
||||
bool check_directory_exists(const std::string& dirname, bool is_exec = false);
|
||||
bool is_absolute_path(std::string filename);
|
||||
void remove_directory(std::string dirname);
|
||||
bool create_directory(const std::string& dirname);
|
||||
std::string escape_filename_spaces(const std::string& filename);
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
#endif // YOSYS_IO_H
|
||||
|
|
|
@ -556,29 +556,29 @@ void init_share_dirname()
|
|||
std::string proc_self_path = proc_self_dirname();
|
||||
# if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR)
|
||||
std::string proc_share_path = proc_self_path + "share\\";
|
||||
if (check_file_exists(proc_share_path, true)) {
|
||||
if (check_directory_exists(proc_share_path, true)) {
|
||||
yosys_share_dirname = proc_share_path;
|
||||
return;
|
||||
}
|
||||
proc_share_path = proc_self_path + "..\\share\\";
|
||||
if (check_file_exists(proc_share_path, true)) {
|
||||
if (check_directory_exists(proc_share_path, true)) {
|
||||
yosys_share_dirname = proc_share_path;
|
||||
return;
|
||||
}
|
||||
# else
|
||||
std::string proc_share_path = proc_self_path + "share/";
|
||||
if (check_file_exists(proc_share_path, true)) {
|
||||
if (check_directory_exists(proc_share_path, true)) {
|
||||
yosys_share_dirname = proc_share_path;
|
||||
return;
|
||||
}
|
||||
proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/";
|
||||
if (check_file_exists(proc_share_path, true)) {
|
||||
if (check_directory_exists(proc_share_path, true)) {
|
||||
yosys_share_dirname = proc_share_path;
|
||||
return;
|
||||
}
|
||||
# ifdef YOSYS_DATDIR
|
||||
proc_share_path = YOSYS_DATDIR "/";
|
||||
if (check_file_exists(proc_share_path, true)) {
|
||||
if (check_directory_exists(proc_share_path, true)) {
|
||||
yosys_share_dirname = proc_share_path;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -252,23 +252,6 @@ inline void memhasher() { if (memhasher_active) memhasher_do(); }
|
|||
void yosys_banner();
|
||||
int ceil_log2(int x) YS_ATTRIBUTE(const);
|
||||
|
||||
int readsome(std::istream &f, char *s, int n);
|
||||
std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
|
||||
std::vector<std::string> split_tokens(const std::string &text, const char *sep = " \t\r\n");
|
||||
bool patmatch(const char *pattern, const char *string);
|
||||
#if !defined(YOSYS_DISABLE_SPAWN)
|
||||
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
|
||||
#endif
|
||||
std::string get_base_tmpdir();
|
||||
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
|
||||
bool check_file_exists(std::string filename, bool is_exec = false);
|
||||
bool check_directory_exists(const std::string& dirname);
|
||||
bool is_absolute_path(std::string filename);
|
||||
void remove_directory(std::string dirname);
|
||||
bool create_directory(const std::string& dirname);
|
||||
std::string escape_filename_spaces(const std::string& filename);
|
||||
|
||||
template<typename T> int GetSize(const T &obj) { return obj.size(); }
|
||||
inline int GetSize(RTLIL::Wire *wire);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue