softwarecontainer  0.18.0-739e8d7 2017-05-04
filetoolkitwithundo.h
1 /*
2  * Copyright (C) 2016-2017 Pelagicore AB
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  *
17  * For further information see LICENSE
18  */
19 
20 #pragma once
21 
22 #include "mountcleanuphandler.h"
23 #include "createdir.h"
24 #include "softwarecontainer-common.h"
25 
26 namespace softwarecontainer {
27 
29 {
30  LOG_DECLARE_CLASS_CONTEXT("CLEA", "File toolkit");
31 
32 public:
34 
43  bool bindMount(const std::string &src,
44  const std::string &dst,
45  const std::string &tmpContainerRoot,
46  bool readOnly,
47  bool writeBufferEnabled=false);
48 
56  bool tmpfsMount(const std::string dst, const int maxSize);
57 
58 protected:
59  /*
60  * @brief Writes to a file (and optionally create it)
61  */
62  bool writeToFile(const std::string &path, const std::string &content);
63 
64  /*
65  * @brief Creates a file cleanup handler for a specific file.
66  *
67  * This is useful if one creates a file in some other way and want it deleted later.
68  */
69  void markFileForDeletion(const std::string &path);
70 
83  bool overlayMount(const std::string &lower,
84  const std::string &upper,
85  const std::string &work,
86  const std::string &dst);
87 
94  bool syncOverlayMount(const std::string &lower,
95  const std::string &upper);
96 
103  bool createSharedMountPoint(const std::string &path);
104 
115  bool pathInList(const std::string path);
116 
121  std::vector<std::unique_ptr<CleanUpHandler>> m_cleanupHandlers;
122 
127  std::vector<std::unique_ptr<CreateDir>> m_createDirList;
128 };
129 
130 } // namespace softwarecontainer
std::vector< std::unique_ptr< CleanUpHandler > > m_cleanupHandlers
m_cleanupHandlers A vector of cleanupHandlers added during the lifetime of the FileToolKitWithUndo th...
bool tmpfsMount(const std::string dst, const int maxSize)
tmpfsMount Mount a tmpfs in the dst path and limit size of the tmpfs to maxSize
std::vector< std::unique_ptr< CreateDir > > m_createDirList
m_createDirList A vector of CreateDir classes.
bool overlayMount(const std::string &lower, const std::string &upper, const std::string &work, const std::string &dst)
overlayMount Mount a directory with an overlay on top of it.
bool pathInList(const std::string path)
checks whether given path is already added to clean up handlers or not
bool createSharedMountPoint(const std::string &path)
createSharedMountPoint Make the mount point shared, ie new mount points created in one bind mount wil...
bool bindMount(const std::string &src, const std::string &dst, const std::string &tmpContainerRoot, bool readOnly, bool writeBufferEnabled=false)
bindMount Bind mount a src directory to another position dst.
bool syncOverlayMount(const std::string &lower, const std::string &upper)
syncOverlayMount Copy the directory structure from upper layer to the lower layer ...
Developers guide to adding a config item: