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(SyscallInterface & syscall,int repeat,const std::string & path_name)22 DeleteFile::DeleteFile(SyscallInterface& syscall, int repeat, const std::string& path_name)
23 : Instruction(syscall, kName, repeat),
24 path_name_(GetAbsolutePath() + path_name),
25 input_key_(-1) {}
26
DeleteFile(SyscallInterface & syscall,int repeat,int input_key)27 DeleteFile::DeleteFile(SyscallInterface& syscall, int repeat, int input_key)
28 : Instruction(syscall, kName, repeat), input_key_(input_key) {}
29
SetUpSingle()30 void DeleteFile::SetUpSingle() {
31 if (input_key_ != -1) {
32 path_name_ = std::get<std::string>(SharedVariables::Get(input_key_));
33 }
34 Instruction::SetUpSingle();
35 }
36
RunSingle()37 void DeleteFile::RunSingle() {
38 if (syscall_.Unlink(path_name_) == -1) {
39 LOGF("Error while calling unlink()");
40 }
41 }
42
43 } // namespace dittosuite
44