Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix windows is_path_invalid, and apply it to directory creation. #88129

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/windows/dir_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#if defined(WINDOWS_ENABLED)

#include "dir_access_windows.h"
#include "file_access_windows.h"

#include "core/config/project_settings.h"
#include "core/os/memory.h"
Expand Down Expand Up @@ -177,6 +178,13 @@ Error DirAccessWindows::make_dir(String p_dir) {
p_dir = fix_path(p_dir);
}

if (FileAccessWindows::is_path_invalid(p_dir)) {
#ifdef DEBUG_ENABLED
WARN_PRINT("The path :" + p_dir + " is a reserved Windows system pipe, so it can't be used for creating directories.");
#endif
return ERR_INVALID_PARAMETER;
}

p_dir = p_dir.simplify_path().replace("/", "\\");

bool success;
Expand Down
7 changes: 1 addition & 6 deletions drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ void FileAccessWindows::check_errors() const {

bool FileAccessWindows::is_path_invalid(const String &p_path) {
// Check for invalid operating system file.
String fname = p_path;
int dot = fname.find(".");
if (dot != -1) {
fname = fname.substr(0, dot);
}
fname = fname.to_lower();
String fname = p_path.get_file().get_basename().to_lower();
return invalid_files.has(fname);
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/windows/file_access_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class FileAccessWindows : public FileAccess {

void _close();

static bool is_path_invalid(const String &p_path);
static HashSet<String> invalid_files;

public:
static bool is_path_invalid(const String &p_path);

virtual String fix_path(const String &p_path) const override;
virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file
virtual bool is_open() const override; ///< true when file is open
Expand Down
Loading