winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

PathPartTable.h (3110B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <winget/SQLiteWrapper.h>
      5 #include <filesystem>
      6 #include <optional>
      7 #include <string>
      8 #include <string_view>
      9 #include <tuple>
     10 
     11 
     12 namespace AppInstaller::Repository::Microsoft::Schema::V1_0
     13 {
     14     // A table that represents the parts of a path
     15     struct PathPartTable
     16     {
     17         // The id type
     18         using id_t = SQLite::rowid_t;
     19 
     20         // The id used when no path is present.
     21         constexpr static id_t NoPathId = -1;
     22 
     23         // Creates the table with named indices.
     24         static void Create(SQLite::Connection& connection);
     25 
     26         // Creates the table with standard primary keys.
     27         static void Create_deprecated(SQLite::Connection& connection);
     28 
     29         // Drops the table.
     30         static void Drop(SQLite::Connection& connection);
     31 
     32         // Gets the table name.
     33         static std::string_view TableName();
     34 
     35         // Gets the value name.
     36         static std::string_view ValueName();
     37 
     38         // Ensure that the given relative path exists within the path parts table.
     39         // If createIfNotFound is true, the function will add the parts as needed.
     40         //      The result bool will indicate whether it was necessary to add the path (true),
     41         //      or it was already present (false).
     42         // If createIfNotFound is false, the function will simply determine if the path is present.
     43         //      The result bool will indicate whether the path was found (true), or not (false).
     44         // In all cases except createIfNotFound == false and result bool == false, the int64_t value
     45         // will be valid and the rowid of the final path part in the path.
     46         // If relativePath is not provided, will always map to an entry with NoPathId.
     47         static std::tuple<bool, SQLite::rowid_t> EnsurePathExists(SQLite::Connection& connection, const std::optional<std::filesystem::path>& relativePath, bool createIfNotFound);
     48 
     49         // Gets the path string using the given id as the leaf.
     50         static std::optional<std::string> GetPathById(const SQLite::Connection& connection, SQLite::rowid_t id);
     51 
     52         // Removes the path that terminates at the given id.
     53         // Will not remove a path part if it is referenced.
     54         static void RemovePathById(SQLite::Connection& connection, SQLite::rowid_t id);
     55 
     56         // Removes data that is no longer needed for an index that is to be published.
     57         static void PrepareForPackaging(SQLite::Connection& connection);
     58 
     59         // Removes data that is no longer needed for an index that is to be published.
     60         static void PrepareForPackaging_deprecated(SQLite::Connection& connection);
     61 
     62         // Checks the consistency of the index to ensure that every referenced row exists.
     63         // Returns true if index is consistent; false if it is not.
     64         static bool CheckConsistency(const SQLite::Connection& connection, bool log);
     65 
     66         // Determines if the table is empty.
     67         static bool IsEmpty(SQLite::Connection& connection);
     68     };
     69 }