mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 12:25:35 +02:00
[cdc_fuse_fs] Fix various issues (#6)
Fixes a couple of issues with the FUSE: - Creates the mount directory if it does not exist. This assumes the mount dir to be the last arg. Ideally, we'd parse the command line and then create the directory, but unfortunately fuse_parse_cmdline already verifies that the dir exists. - Expands the cache_dir (e.g. ~). - Fixes a compile issue in manifest_iterator.
This commit is contained in:
@@ -35,16 +35,18 @@ cc_library(
|
||||
# Additional warnings from @com_github_dirent
|
||||
"/wd4505", # unreferenced function with internal linkage has been removed
|
||||
],
|
||||
"//conditions:default": ["/wd4505"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
":path",
|
||||
":platform",
|
||||
"@com_github_dirent//:dirent",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
],
|
||||
] + select({
|
||||
"//tools:windows": ["@com_github_dirent//:dirent"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
cc_test(
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <stdlib.h> // putenv
|
||||
#include <unistd.h> // readlink
|
||||
#include <utime.h> // struct utimbuf
|
||||
#include <wordexp.h>
|
||||
#define __stat64 stat64
|
||||
#define _chmod chmod
|
||||
#endif
|
||||
@@ -198,8 +199,8 @@ absl::Status GetKnownFolderPath(FolderId folder_id, std::string* path) {
|
||||
}
|
||||
#endif
|
||||
|
||||
absl::Status ExpandPathVariables(std::string* path) {
|
||||
#if PLATFORM_WINDOWS
|
||||
absl::Status ExpandEnvironmentPathVariables(std::string* path) {
|
||||
std::wstring wchar_path = Util::Utf8ToWideStr(*path);
|
||||
|
||||
DWORD size = ::ExpandEnvironmentStrings(wchar_path.c_str(), nullptr, 0);
|
||||
@@ -217,8 +218,18 @@ absl::Status ExpandEnvironmentPathVariables(std::string* path) {
|
||||
wchar_expanded.pop_back();
|
||||
*path = Util::WideToUtf8Str(wchar_expanded);
|
||||
return absl::OkStatus();
|
||||
}
|
||||
#else
|
||||
wordexp_t res;
|
||||
wordexp(path->c_str(), &res, 0);
|
||||
if (res.we_wordc > 1) {
|
||||
return absl::InvalidArgumentError(
|
||||
"Path expands to multiple results (did you use * etc. ?");
|
||||
}
|
||||
*path = res.we_wordv[0];
|
||||
wordfree(&res);
|
||||
return absl::OkStatus();
|
||||
#endif
|
||||
}
|
||||
|
||||
absl::Status GetEnv(const std::string& name, std::string* value) {
|
||||
value->clear();
|
||||
|
||||
@@ -99,12 +99,15 @@ enum class FolderId {
|
||||
|
||||
// Returns the Windows known folder path for the given |folder_id|.
|
||||
absl::Status GetKnownFolderPath(FolderId folder_id, std::string* path);
|
||||
|
||||
// Expands environment path variables like %APPDATA%. Variables are matched
|
||||
// case invariantly. Unknown environment variables are not changed.
|
||||
absl::Status ExpandEnvironmentPathVariables(std::string* path);
|
||||
#endif
|
||||
|
||||
// Expands environment path variables like %APPDATA% on Windows or ~ on Linux.
|
||||
// On Windows, variables are matched case invariantly. Unknown environment
|
||||
// variables are not changed.
|
||||
// On Linux, performs a shell-like expansion. Returns an error if multiple
|
||||
// results would be returned, e.g. from *.txt.
|
||||
absl::Status ExpandPathVariables(std::string* path);
|
||||
|
||||
// Returns the environment variable with given |name| in |value|.
|
||||
// Returns a NotFound error and sets |value| to an empty string if the variable
|
||||
// does not exist.
|
||||
|
||||
@@ -199,22 +199,34 @@ TEST_F(PathTest, GetKnownFolderPath) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(PathTest, ExpandPathVariables) {
|
||||
#if PLATFORM_WINDOWS
|
||||
TEST_F(PathTest, ExpandEnvironmentPathVariables) {
|
||||
std::string path = u8"%userPROfile%\\fOo\U0001F964";
|
||||
EXPECT_OK(path::ExpandEnvironmentPathVariables(&path));
|
||||
EXPECT_OK(path::ExpandPathVariables(&path));
|
||||
EXPECT_TRUE(absl::StartsWith(path, "C:\\Users\\")) << path;
|
||||
EXPECT_TRUE(absl::EndsWith(path, u8"\\fOo\U0001F964")) << path;
|
||||
|
||||
path = "%ProgramFiles(x86)%\\Foo";
|
||||
EXPECT_OK(path::ExpandEnvironmentPathVariables(&path));
|
||||
EXPECT_OK(path::ExpandPathVariables(&path));
|
||||
EXPECT_EQ(path, "C:\\Program Files (x86)\\Foo");
|
||||
|
||||
path = "%unrelated%\\fOo";
|
||||
EXPECT_OK(path::ExpandEnvironmentPathVariables(&path));
|
||||
EXPECT_OK(path::ExpandPathVariables(&path));
|
||||
EXPECT_EQ(path, "%unrelated%\\fOo") << path;
|
||||
}
|
||||
#else
|
||||
std::string path = u8"fooU0001F964";
|
||||
EXPECT_OK(path::ExpandPathVariables(&path));
|
||||
EXPECT_EQ(path, u8"fooU0001F964");
|
||||
|
||||
path = "~/foo";
|
||||
EXPECT_OK(path::ExpandPathVariables(&path));
|
||||
EXPECT_TRUE(absl::StrContains(path, "home")) << path;
|
||||
|
||||
path = "*";
|
||||
EXPECT_ERROR_MSG(InvalidArgument, "multiple results",
|
||||
path::ExpandPathVariables(&path));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(PathTest, GetEnv_DoesNotExist) {
|
||||
std::string value;
|
||||
|
||||
Reference in New Issue
Block a user