Skip to content

Commit

Permalink
Merge branch 'main' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Dec 26, 2024
2 parents 20d13cf + c1bdf6b commit 2647cc0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 49 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Checks: >
readability-*,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
-readability-braces-around-statements,
-readability-function-cognitive-complexity,
Expand Down
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# clang-format all files in main branch
c84b89b4826b64b05a176eb15725ba526495c6a1
# clang-format all files in beta branch
94080d3c784032dd0a67dc903f0e92d9cb1ce538
79 changes: 33 additions & 46 deletions base/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,38 @@ std::string normalize_path(const std::string& _path)
// Replace multiple slashes with a single path_separator.
std::string path = fix_path_separators(_path);

std::vector<std::string> parts;
split_string(path, parts, path_separators);

std::vector<std::string> fn_parts;
const bool has_root = (!path.empty() && path[0] == path_separator);
const bool last_dot = (parts.back() == ".");
const bool last_slash = parts.back().empty();
if (last_slash || last_dot)
parts.pop_back();

for (const auto& part : parts) {
// Skip each dot part.
if (part.empty() || part == ".")
continue;
if (part == "..") {
if (has_root && fn_parts.empty())
continue;
if (!fn_parts.empty() && fn_parts.back() != "..")
fn_parts.pop_back();
else
fn_parts.push_back(part);
}
else
fn_parts.push_back(part);
}

// Reconstruct the filename 'fn' from 'fn_parts'
std::string fn;
fn.reserve(path.size());

// Add the first separator for absolute paths.
if (!path.empty() && path[0] == path_separator) {
if (has_root) {
fn.push_back(path_separator);

#if LAF_WINDOWS
// Add the second separator for network paths.
if (path.size() >= 2 && path[1] == path_separator) {
Expand All @@ -296,51 +321,13 @@ std::string normalize_path(const std::string& _path)
#endif
}

std::vector<std::string> parts;
split_string(path, parts, path_separators);

// Last element generates a final dot or slash in normalized path.
bool last_dot = false;

auto n = int(parts.size());
for (int i = 0; i < n; ++i) {
const auto& part = parts[i];
for (const auto& part : fn_parts)
fn = join_path(fn, part);

// Remove each dot part.
if (part == ".") {
last_dot = true;

if (i + 1 == n)
break;

fn = join_path(fn, std::string());
continue;
}

if (!part.empty())
last_dot = false;
if (!fn.empty() && parts.back() != ".." && (last_slash || last_dot))
fn.push_back(path_separator);

if (part != ".." && i + 1 < n && parts[i + 1] == "..") {
// Skip this "part/.."
++i;
last_dot = true;
}
else if (!part.empty()) {
fn = join_path(fn, part);
}
else
last_dot = true;
}
if (last_dot) {
if (fn.empty())
fn = ".";
else if (fn.back() != path_separator &&
// Don't include trailing slash for ".." filename
get_file_name(fn) != "..") {
fn.push_back(path_separator);
}
}
return fn;
return (fn.empty() ? "." : fn);
}

bool has_file_extension(const std::string& filename, const base::paths& extensions)
Expand Down
7 changes: 7 additions & 0 deletions base/fs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ TEST(FS, GetAbsolutePath)

#if LAF_WINDOWS
EXPECT_EQ("C:\\file", get_absolute_path("C:/path/../file"));
EXPECT_EQ("C:\\user\\file", get_absolute_path("C:/user/name/path/../../file"));
EXPECT_EQ("C:\\file", get_absolute_path("C:/user/name/path/../../../file"));
EXPECT_EQ("C:\\path\\file", get_absolute_path("C:/user/name/..//.././path/tag/../file"));
#else
EXPECT_EQ("/file", get_absolute_path("/path/../file"));
EXPECT_EQ("/user/file", get_absolute_path("/user/name/path/../../file"));
EXPECT_EQ("/file", get_absolute_path("/user/name/path/../../../file"));
EXPECT_EQ("/path/file", get_absolute_path("/user/name/..//.././path/tag/../file"));
#endif
}

Expand Down Expand Up @@ -288,6 +294,7 @@ TEST(FS, NormalizePath)
EXPECT_EQ(".", normalize_path("a/.."));
EXPECT_EQ("..", normalize_path("../a/.."));
EXPECT_EQ(".." + sep + "..", normalize_path("../a/../.."));
EXPECT_EQ(".." + sep + "..", normalize_path("../a/../../"));
EXPECT_EQ("..", normalize_path("a/../.."));
EXPECT_EQ(sep + "b", normalize_path("/a/../b"));

Expand Down
8 changes: 5 additions & 3 deletions os/x11/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,9 @@ void WindowX11::processX11Event(XEvent& event)
XSendEvent(m_display, sourceWindow, 0, 0, &event2);
}
else if (event.xclient.message_type == XdndDrop) {
// The time stamp must be passed to XConvertSelection
// to insure that the correct data is received.
const Time time = event.xclient.data.l[2];
const ::Window sourceWindow = (::Window)event.xclient.data.l[0];

ASSERT(g_dndData);
Expand All @@ -1368,7 +1371,7 @@ void WindowX11::processX11Event(XEvent& event)
URI_LIST,
XdndSelection,
m_window,
CurrentTime);
time);
}
}
break;
Expand Down Expand Up @@ -1436,7 +1439,6 @@ void WindowX11::processX11Event(XEvent& event)
XFree(prop);
}

const ::Window root = XDefaultRootWindow(m_display);
XEvent event2;
memset(&event2, 0, sizeof(event2));
event2.xany.type = ClientMessage;
Expand All @@ -1448,7 +1450,7 @@ void WindowX11::processX11Event(XEvent& event)
event2.xclient.data.l[1] = (successful ? 1 : 0);
event2.xclient.data.l[2] = 0;
event2.xclient.data.l[3] = 0;
XSendEvent(m_display, root, 0, 0, &event2);
XSendEvent(m_display, g_dndData->sourceWindow, 0, 0, &event2);

// Delete temporary data.
g_dndData.reset();
Expand Down

0 comments on commit 2647cc0

Please sign in to comment.