• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 Huawei Technologies Co., Ltd
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_
18 #define MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_
19 
20 #include <string>
21 #include <unordered_set>
22 #include "mindapi/base/macros.h"
23 #include "utils/ms_utils.h"
24 
25 namespace mindspore {
26 // Manager for auto delete temp files
27 class MS_CORE_API TempFileManager {
28  public:
29   static TempFileManager &GetInstance();
30   /// \brief register temp file which will delete when process exits.
31   ///
32   /// \param[in] the temp file path.
33   void Register(const std::string &file_path);
34 
35   /// \brief unregister temp file which is no need to delete when process exits.
36   ///
37   /// \param[in] the file path.
38   void UnRegister(const std::string &file_path);
39 
40   /// \brief delete file.
41   ///
42   /// \param[in] the file path.
43   void RemoveFile(const std::string &file_path) const;
44 
45   /// \brief delete all temp files
46   void CleanTempFiles();
47 
48  private:
49   TempFileManager() = default;
50   ~TempFileManager();
51   DISABLE_COPY_AND_ASSIGN(TempFileManager)
52   std::unordered_set<std::string> temp_file_paths_;
53 };
54 }  // namespace mindspore
55 #endif  // MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_
56