1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
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
16 #include "mtpfs_type_tmp_file.h"
17
MtpFsTypeTmpFile()18 MtpFsTypeTmpFile::MtpFsTypeTmpFile() : pathDevice_(), pathTmp_(), fileDescriptors_(), modified_(false) {}
19
MtpFsTypeTmpFile(const std::string & pathDevice,const std::string & pathTmp,int fileDesc,bool modified)20 MtpFsTypeTmpFile::MtpFsTypeTmpFile(const std::string &pathDevice, const std::string &pathTmp, int fileDesc,
21 bool modified)
22 : pathDevice_(pathDevice), pathTmp_(pathTmp), modified_(modified)
23 {
24 fileDescriptors_.insert(fileDesc);
25 }
26
MtpFsTypeTmpFile(const MtpFsTypeTmpFile & copy)27 MtpFsTypeTmpFile::MtpFsTypeTmpFile(const MtpFsTypeTmpFile ©)
28 : pathDevice_(copy.pathDevice_),
29 pathTmp_(copy.pathTmp_),
30 fileDescriptors_(copy.fileDescriptors_),
31 modified_(copy.modified_)
32 {}
33
HasFileDescriptor(int fd)34 bool MtpFsTypeTmpFile::HasFileDescriptor(int fd)
35 {
36 auto it = std::find(fileDescriptors_.begin(), fileDescriptors_.end(), fd);
37 return it != fileDescriptors_.end();
38 }
39
RemoveFileDescriptor(int fd)40 void MtpFsTypeTmpFile::RemoveFileDescriptor(int fd)
41 {
42 auto it = std::find(fileDescriptors_.begin(), fileDescriptors_.end(), fd);
43 if (it == fileDescriptors_.end()) {
44 return;
45 }
46 fileDescriptors_.erase(it);
47 }
48
operator =(const MtpFsTypeTmpFile & rhs)49 MtpFsTypeTmpFile &MtpFsTypeTmpFile::operator = (const MtpFsTypeTmpFile &rhs)
50 {
51 pathDevice_ = rhs.pathDevice_;
52 pathTmp_ = rhs.pathTmp_;
53 fileDescriptors_ = rhs.fileDescriptors_;
54 modified_ = rhs.modified_;
55 return *this;
56 }
57