1 /* 2 * Copyright (C) 2023 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 "memory_filesystem.h" 17 18 #include <core/namespace.h> 19 20 #include "memory_file.h" 21 22 CORE_BEGIN_NAMESPACE() 23 using BASE_NS::string; 24 using BASE_NS::string_view; 25 using BASE_NS::vector; 26 GetEntry(const string_view path)27IDirectory::Entry MemoryFilesystem::GetEntry(const string_view path) 28 { 29 if (auto const pos = memoryFiles_.find(path); pos != memoryFiles_.end()) { 30 return { IDirectory::Entry::FILE, string(path), 0 }; 31 } 32 return {}; 33 } OpenFile(const string_view path)34IFile::Ptr MemoryFilesystem::OpenFile(const string_view path) 35 { 36 if (auto const pos = memoryFiles_.find(path); pos != memoryFiles_.end()) { 37 auto storage = pos->second.lock(); 38 if (storage) { 39 return IFile::Ptr { new MemoryFile(BASE_NS::move(storage)) }; 40 } 41 } 42 return IFile::Ptr(); 43 } 44 CreateFile(const string_view path)45IFile::Ptr MemoryFilesystem::CreateFile(const string_view path) 46 { 47 if (auto const pos = memoryFiles_.find(path); pos != memoryFiles_.end()) { 48 return IFile::Ptr { new MemoryFile(pos->second.lock()) }; 49 } 50 auto storage = std::make_shared<MemoryFileStorage>(); 51 memoryFiles_[path] = storage; 52 53 return IFile::Ptr { new MemoryFile(BASE_NS::move(storage)) }; 54 } 55 DeleteFile(const string_view path)56bool MemoryFilesystem::DeleteFile(const string_view path) 57 { 58 return memoryFiles_.erase(path) != memoryFiles_.end(); 59 } 60 OpenDirectory(const string_view path)61IDirectory::Ptr MemoryFilesystem::OpenDirectory(const string_view path) 62 { 63 return IDirectory::Ptr(); 64 } 65 CreateDirectory(const string_view path)66IDirectory::Ptr MemoryFilesystem::CreateDirectory(const string_view path) 67 { 68 return IDirectory::Ptr(); 69 } 70 DeleteDirectory(const string_view path)71bool MemoryFilesystem::DeleteDirectory(const string_view path) 72 { 73 return false; 74 } 75 Rename(const string_view fromPath,const string_view toPath)76bool MemoryFilesystem::Rename(const string_view fromPath, const string_view toPath) 77 { 78 return false; 79 } 80 GetUriPaths(const string_view) const81vector<string> MemoryFilesystem::GetUriPaths(const string_view) const 82 { 83 return {}; 84 } 85 CORE_END_NAMESPACE() 86