/* common/KMOstreeMutableTree.h
 *
 * Copyright (C) 2023 OpenKylin, Inc
 */

#ifndef __KMOSTREEMUTABLETREE_H__
#define __KMOSTREEMUTABLETREE_H__

#include <ostree.h>

#include <memory>
#include <string>

/**
 * @brief ostree mutable tree
 */
class KMOstreeMutableTree
{
public:
    KMOstreeMutableTree();
    KMOstreeMutableTree(OstreeMutableTree *tree);
    KMOstreeMutableTree(const KMOstreeMutableTree &other);
    ~KMOstreeMutableTree();

    KMOstreeMutableTree &operator=(const KMOstreeMutableTree &other);

    void setMetadataChecksum(const char *checksum);

    // 返回文件名为name的仓库子目录树，如果不存在，则创建一个空的子目录。
    bool ensureDir(const std::string &name, KMOstreeMutableTree &outSubdir);

    bool replaceFile(const char *name, const char *checksum);

    // 获取最后一次错误信息
    std::string errorMessage() const;

    OstreeMutableTree *get();

private:
    class Private;
    std::shared_ptr<Private> d = nullptr;
};

#endif // !__KMOSTREEMUTABLETREE_H__
