1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <ditto/delete_file.h>
16
17 #include <ditto/logger.h>
18 #include <ditto/shared_variables.h>
19
20 namespace dittosuite {
21
DeleteFile(const Params & params,const std::string & path_name)22 DeleteFile::DeleteFile(const Params& params, const std::string& path_name)
23 : Instruction(kName, params), path_name_(GetAbsolutePath() + path_name), input_key_(-1) {}
24
DeleteFile(const Params & params,int input_key)25 DeleteFile::DeleteFile(const Params& params, int input_key)
26 : Instruction(kName, params), input_key_(input_key) {}
27
SetUpSingle()28 void DeleteFile::SetUpSingle() {
29 if (input_key_ != -1) {
30 path_name_ = std::get<std::string>(SharedVariables::Get(input_key_));
31 }
32 Instruction::SetUpSingle();
33 }
34
RunSingle()35 void DeleteFile::RunSingle() {
36 if (syscall_.Unlink(path_name_) == -1) {
37 LOGF("Error while calling unlink()");
38 }
39 }
40
41 } // namespace dittosuite
42