szaszm commented on code in PR #1634: URL: https://github.com/apache/nifi-minifi-cpp/pull/1634#discussion_r1331595144
########## extensions/smb/PutSmb.cpp: ########## @@ -0,0 +1,94 @@ +/** + * + * 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 "PutSmb.h" +#include "utils/gsl.h" +#include "utils/ProcessorConfigUtils.h" +#include "utils/OsUtils.h" +#include "utils/file/FileWriterCallback.h" +#include "core/Resource.h" + +namespace org::apache::nifi::minifi::extensions::smb { + +void PutSmb::initialize() { + setSupportedProperties(Properties); + setSupportedRelationships(Relationships); +} + +void PutSmb::onSchedule(core::ProcessContext* context, core::ProcessSessionFactory*) { + gsl_Expects(context); + smb_connection_controller_service_ = SmbConnectionControllerService::getFromProperty(*context, PutSmb::ConnectionControllerService); + create_missing_dirs_ = context->getProperty<bool>(PutSmb::CreateMissingDirectories).value_or(true); + conflict_resolution_strategy_ = utils::parseEnumProperty<FileExistsResolutionStrategy>(*context, ConflictResolution); +} + +std::filesystem::path PutSmb::getFilePath(core::ProcessContext& context, const std::shared_ptr<core::FlowFile>& flow_file) { + auto filename = flow_file->getAttribute(core::SpecialFlowAttribute::FILENAME).value_or(flow_file->getUUIDStr()); + return smb_connection_controller_service_->getPath() / context.getProperty(Directory, flow_file).value_or("") / filename; +} + +void PutSmb::onTrigger(core::ProcessContext* context, core::ProcessSession* session) { + gsl_Expects(context && session && smb_connection_controller_service_); + + if (auto connection_error = smb_connection_controller_service_->validateConnection()) { + logger_->log_error("Couldn't establish connection to the specified network location due to %s", connection_error.message()); + context->yield(); + return; + } + + auto flow_file = session->get(); + if (!flow_file) { + context->yield(); + return; + } + + auto full_file_path = getFilePath(*context, flow_file); + + if (utils::file::exists(full_file_path)) { + logger_->log_warn("Destination file %s exists; applying Conflict Resolution Strategy: %s", full_file_path.string(), std::string(magic_enum::enum_name(conflict_resolution_strategy_))); Review Comment: I'm not sure a warning is appropriate for every preexisting file, especially if the user asked to ignore it. We can keep it if you think it's better, but I'm afraid of log spamming in some scenarios. -- 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]
