szaszm commented on code in PR #1634:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1634#discussion_r1300087309


##########
libminifi/src/utils/file/FileUtils.cpp:
##########
@@ -96,4 +100,22 @@ std::filesystem::file_time_type 
from_sys(std::chrono::system_clock::time_point s
 #endif
 }
 
+#ifdef WIN32
+std::chrono::file_clock::time_point fileTimePointFromFileTime(const FILETIME& 
filetime) {
+  static_assert(std::ratio_equal_v<std::chrono::file_clock::duration::period, 
std::ratio<1, 10000000>>, "file_clock duration must be 100 nanoseconds");

Review Comment:
   ```suggestion
     
static_assert(std::ratio_equal_v<std::chrono::file_clock::duration::period, 
std::ratio<1, 10000000>>, "file_clock duration tick period must be 100 
nanoseconds");
   ```



##########
libminifi/src/utils/file/FileUtils.cpp:
##########
@@ -96,4 +100,22 @@ std::filesystem::file_time_type 
from_sys(std::chrono::system_clock::time_point s
 #endif
 }
 
+#ifdef WIN32
+std::chrono::file_clock::time_point fileTimePointFromFileTime(const FILETIME& 
filetime) {
+  static_assert(std::ratio_equal_v<std::chrono::file_clock::duration::period, 
std::ratio<1, 10000000>>, "file_clock duration must be 100 nanoseconds");
+  std::chrono::file_clock::duration 
duration{(static_cast<int64_t>(filetime.dwHighDateTime) << 32) | 
filetime.dwLowDateTime};
+  return std::chrono::file_clock::time_point{duration};
+}
+
+nonstd::expected<WindowsFileTimes, std::error_code> getWindowsFileTimes(const 
std::filesystem::path& path) {
+  WIN32_FILE_ATTRIBUTE_DATA file_attributes;
+  auto get_file_attributes_result = GetFileAttributesExW(path.c_str(), 
GetFileExInfoStandard, &file_attributes);
+  if (!get_file_attributes_result)
+    return 
nonstd::make_unexpected(utils::OsUtils::windowsErrorToErrorCode(GetLastError()));
+  return WindowsFileTimes{.creation_time = 
fileTimePointFromFileTime(file_attributes.ftCreationTime),
+                          .last_access_time = 
fileTimePointFromFileTime(file_attributes.ftLastAccessTime),
+                          .last_write_time = 
fileTimePointFromFileTime(file_attributes.ftLastWriteTime)};
+}

Review Comment:
   I'd rename the type, and implement the functionality on POSIX as well. 
`stat` returns all of this info on POSIX.



##########
libminifi/src/utils/file/FileUtils.cpp:
##########
@@ -96,4 +100,22 @@ std::filesystem::file_time_type 
from_sys(std::chrono::system_clock::time_point s
 #endif
 }
 
+#ifdef WIN32
+std::chrono::file_clock::time_point fileTimePointFromFileTime(const FILETIME& 
filetime) {
+  static_assert(std::ratio_equal_v<std::chrono::file_clock::duration::period, 
std::ratio<1, 10000000>>, "file_clock duration must be 100 nanoseconds");
+  std::chrono::file_clock::duration 
duration{(static_cast<int64_t>(filetime.dwHighDateTime) << 32) | 
filetime.dwLowDateTime};
+  return std::chrono::file_clock::time_point{duration};

Review Comment:
   This relies on an unspecified epoch on the C++ side, which happens to be the 
same as that of FILETIME, January 1, 1601. Is there any way to avoid or check 
this?
   
   I'm not sure if it matters, but the code could be written to be agnostic of 
the ratio of `file_clock`, and just construct a `file_clock::duration` from a 
duration of with 100ns steps, like `FILETIME`.



##########
extensions/smb/FetchSmb.cpp:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 "FetchSmb.h"
+#include "core/Resource.h"
+#include "utils/file/FileReaderCallback.h"
+
+namespace org::apache::nifi::minifi::extensions::smb {
+
+void FetchSmb::initialize() {
+  setSupportedProperties(Properties);
+  setSupportedRelationships(Relationships);
+}
+
+void FetchSmb::onSchedule(const std::shared_ptr<core::ProcessContext>& 
context, const std::shared_ptr<core::ProcessSessionFactory>&) {
+  gsl_Expects(context);
+  if (auto connection_controller_name = 
context->getProperty(FetchSmb::ConnectionControllerService)) {
+    smb_connection_controller_service_ = 
std::dynamic_pointer_cast<SmbConnectionControllerService>(context->getControllerService(*connection_controller_name));
+  }
+  if (!smb_connection_controller_service_) {
+    throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, 
"Missing SMB Connection Controller Service");
+  }

Review Comment:
   Maybe we should make this optional, to support cases, where the system 
automatically mounts the affected SMB shares. I've worked in corporate 
environments where shares are automounted and assigned drive letters on login.



-- 
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]

Reply via email to