2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 * @author Dongsun Lee (ds73.lee@samsung.com)
36 using FilePtr = std::unique_ptr<File>;
42 inline bool isInApp() const noexcept
44 return this->isPackage() && !this->isPreloaded();
47 inline bool isPackage() const noexcept
49 return this->m_type & static_cast<int>(Type::Package);
52 inline bool isPreloaded() const noexcept
54 return this->m_type & static_cast<int>(Type::PreLoaded);
57 inline bool isModified() const noexcept
59 return this->m_type & static_cast<int>(Type::Modified);
62 inline bool isModifiedSince(time_t since) const noexcept
64 return this->m_statptr->st_ctime > since;
67 inline bool isDir() const noexcept
69 return this->m_type & static_cast<int>(Type::Directory);
72 inline const std::string &getName() const noexcept
74 return (this->isInApp()) ? this->m_appPkgPath : this->m_path;
77 inline const std::string &getPath() const noexcept
82 inline const std::string &getAppPkgId() const noexcept
84 return this->m_appPkgId;
87 inline const std::string &getAppUser() const noexcept
89 return this->m_appUser;
92 inline const std::string &getAppPkgPath() const noexcept
94 return this->m_appPkgPath;
99 // throws FileNotExist and FileSystemError
100 static FilePtr create(const std::string &fpath, const FilePtr &parentdir,
101 time_t modifiedSince = -1);
102 static FilePtr createIfModified(const std::string &fpath, const FilePtr &parentdir,
103 time_t modifiedSince = -1);
105 static std::string getPkgPath(const std::string &path);
108 enum class Type : int {
111 PreLoaded = (1 << 2),
116 static FilePtr createInternal(const std::string &fpath, const FilePtr &parentdir,
117 time_t modifiedSince, bool isModifiedOnly);
118 static int getPkgTypes(const std::string &user, const std::string &pkgid);
120 explicit File(const std::string &fpath, const FilePtr &parentdir, int type,
121 std::unique_ptr<struct stat> &&statptr);
125 std::unique_ptr<struct stat> m_statptr;
126 std::string m_appPkgId; // meaningful only if inApp == true
127 std::string m_appUser; // meaningful only if inApp == true
128 std::string m_appPkgPath; // meaningful only if inApp == true
131 // visitor traverses file which is modified since the time of 'modifiedSince'
132 // if modifiedSince is -1, traverse regardless of time
134 using FsVisitorPtr = std::unique_ptr<FsVisitor>;
142 // throws FileNotExist and FileSystemError
143 static FsVisitorPtr create(const std::string &dirpath, bool isBasedOnName,
144 time_t modifiedSince = -1);
147 using DirPtr = std::unique_ptr<DIR, int(*)(DIR *)>;
149 static DirPtr openDir(const std::string &);
151 FsVisitor(const std::string &dirpath, bool isBasedOnName, time_t modifiedSince = -1);
154 std::queue<FilePtr> m_dirs;
156 struct dirent *m_entryBuf;
157 FilePtr m_currentdir;
159 bool m_isBasedOnName;