File indexing completed on 2024-05-19 16:49:48

0001 // SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef MERGEDVFS_H
0006 #define MERGEDVFS_H
0007 
0008 #include <git2.h>
0009 uint qHash(git_oid pOid);
0010 bool operator ==(const git_oid &pOidA, const git_oid &pOidB);
0011 #include <QHash>
0012 #include <QObject>
0013 
0014 #include <QUrl>
0015 
0016 #include <sys/stat.h>
0017 
0018 struct VersionData {
0019     VersionData(bool pChunkedFile, const git_oid *pOid, qint64 pCommitTime, qint64 pModifiedDate)
0020        :mChunkedFile(pChunkedFile), mOid(*pOid), mCommitTime(pCommitTime), mModifiedDate(pModifiedDate)
0021     {
0022         mSizeIsValid = false;
0023     }
0024 
0025     VersionData(const git_oid *pOid, qint64 pCommitTime, qint64 pModifiedDate, quint64 pSize)
0026         :mChunkedFile(false), mOid(*pOid), mCommitTime(pCommitTime), mModifiedDate(pModifiedDate), mSize(pSize)
0027     {
0028         mSizeIsValid = true;
0029     }
0030 
0031     quint64 size();
0032     bool mSizeIsValid;
0033     bool mChunkedFile;
0034     git_oid mOid;
0035     qint64 mCommitTime;
0036     qint64 mModifiedDate;
0037 
0038 protected:
0039     quint64 mSize{};
0040 };
0041 
0042 class MergedNode;
0043 typedef QList<MergedNode*> MergedNodeList;
0044 typedef QListIterator<MergedNode*> MergedNodeListIterator;
0045 typedef QList<VersionData *> VersionList;
0046 typedef QListIterator<VersionData *> VersionListIterator;
0047 
0048 class MergedNode: public QObject {
0049     Q_OBJECT
0050     friend struct VersionData;
0051 public:
0052     MergedNode(QObject *pParent, const QString &pName, uint pMode);
0053     ~MergedNode() override {
0054         delete mSubNodes;
0055         while (!mVersionList.isEmpty()) delete mVersionList.takeFirst();
0056     }
0057     bool isDirectory() const { return S_ISDIR(mMode); }
0058     void getBupUrl(int pVersionIndex, QUrl *pComplete, QString *pRepoPath = nullptr, QString *pBranchName = nullptr,
0059                    qint64 *pCommitTime = nullptr, QString *pPathInRepo = nullptr) const;
0060     virtual MergedNodeList &subNodes();
0061     const VersionList *versionList() const { return &mVersionList; }
0062     uint mode() const { return mMode; }
0063     static void askForIntegrityCheck();
0064 
0065 protected:
0066     virtual void generateSubNodes();
0067 
0068     static git_repository *mRepository;
0069     uint mMode;
0070     VersionList mVersionList;
0071     MergedNodeList *mSubNodes;
0072 };
0073 
0074 class MergedRepository: public MergedNode {
0075     Q_OBJECT
0076 public:
0077     MergedRepository(QObject *pParent, const QString &pRepositoryPath, QString pBranchName);
0078     ~MergedRepository() override;
0079 
0080     bool open();
0081     bool readBranch();
0082     bool permissionsOk();
0083 
0084     QString mBranchName;
0085 };
0086 
0087 #endif // MERGEDVFS_H