Add timeout parameter to update_cached_repo().

This commit is contained in:
tastytea 2020-10-14 03:38:25 +02:00
parent 6cf543a7b4
commit 8f5e9ec7e0
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 11 additions and 6 deletions

View File

@ -48,7 +48,6 @@ using std::runtime_error;
using std::string; using std::string;
using std::string_view; using std::string_view;
using std::to_string; using std::to_string;
using std::uint64_t;
using std::uint8_t; using std::uint8_t;
using std::this_thread::sleep_for; using std::this_thread::sleep_for;
@ -218,10 +217,10 @@ string get_branch_name()
return "web-" + to_string(id); return "web-" + to_string(id);
} }
void update_cached_repo() void update_cached_repo(const uint8_t timeout)
{ {
bool lock_created{false}; bool lock_created{false};
for (uint8_t counter{0}; counter < 20; ++counter) for (uint8_t counter{0}; counter < timeout; ++counter)
{ {
if ((lock_created = files::create_lockfile())) if ((lock_created = files::create_lockfile()))
{ {

View File

@ -28,7 +28,7 @@ namespace FediBlock::git
{ {
using std::string; using std::string;
using std::uint64_t; using std::uint8_t;
/*! /*!
* @brief Initialize libgit and _repo_dir. * @brief Initialize libgit and _repo_dir.
@ -75,8 +75,14 @@ void push();
// Get the name of the branch we use. // Get the name of the branch we use.
string get_branch_name(); string get_branch_name();
// If cached repo exist, pull. If not, clone. /*!
void update_cached_repo(); * @brief If cached repo exist, pull --force. If not, clone.
*
* @param timeout Try to create lockfile for this many seconds. Default is 20.
*
* @since 0.1.0
*/
void update_cached_repo(uint8_t timeout = 20);
} // namespace FediBlock::git } // namespace FediBlock::git