Copilot commented on code in PR #888:
URL: https://github.com/apache/incubator-graphar/pull/888#discussion_r2911476634
##########
cpp/src/graphar/graph_info.cc:
##########
@@ -1485,4 +1468,25 @@ Status GraphInfo::Save(const std::string& path) const {
return fs->WriteValueToFile(yaml_content, no_url_path);
}
+namespace util {
+std::string PathToDirectory(const std::string& path) {
+ if (path.rfind("s3://", 0) == 0) {
+ size_t t = path.find_last_of('?');
+ // Your fix here
Review Comment:
This is a leftover debug/placeholder comment that should be removed before
merging. It doesn't describe the logic and reads like a TODO marker from
development.
##########
cpp/src/graphar/graph_info.cc:
##########
@@ -1485,4 +1468,25 @@ Status GraphInfo::Save(const std::string& path) const {
return fs->WriteValueToFile(yaml_content, no_url_path);
}
+namespace util {
+std::string PathToDirectory(const std::string& path) {
+ if (path.rfind("s3://", 0) == 0) {
+ size_t t = path.find_last_of('?');
+ // Your fix here
+ std::string prefix = (t == std::string::npos) ? path : path.substr(0, t);
+ std::string suffix = (t == std::string::npos) ? "" : path.substr(t);
+
+ const size_t last_slash_idx = prefix.rfind('/');
+ if (std::string::npos != last_slash_idx) {
+ return prefix.substr(0, last_slash_idx + 1) + suffix;
+ }
+ } else {
+ const size_t last_slash_idx = path.rfind('/');
+ if (std::string::npos != last_slash_idx) {
+ return path.substr(0, last_slash_idx + 1);
+ }
+ }
+ return path;
+}
+} // namespace util
Review Comment:
The `PathToDirectory` function definition is placed in `graph_info.cc`, but
it is declared in `util.h` and the natural implementation file for
`graphar::util` functions is `util.cc` (which already exists at
`cpp/src/graphar/util.cc` and contains the other `graphar::util` function
definitions). Moving the definition to `util.cc` would be consistent with the
existing codebase organization and avoid mixing unrelated concerns in
`graph_info.cc`.
##########
cpp/test/test_util.cc:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <iostream>
+#include <string>
+
+#include <catch2/catch_test_macros.hpp>
+#include "./util.h"
+#include "graphar/util.h"
+
+namespace graphar {
+
+TEST_CASE_METHOD(GlobalFixture, "PathUtilTest") {
Review Comment:
Using `GlobalFixture` here means these pure string-manipulation tests will
throw a `std::runtime_error` if the `GAR_TEST_DATA` environment variable is not
set, even though these tests don't use any test data files at all. Consider
using a plain `TEST_CASE` instead of `TEST_CASE_METHOD(GlobalFixture, ...)` so
these unit tests can run without that environment dependency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]