diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-05-16 17:58:22 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-05-16 17:58:22 +0300 |
commit | 879ea25c6c32f51671d11140abf0f478c47b3101 (patch) | |
tree | e6785554254a0505fd7eb1a4f03d9480db4b915b | |
parent | 76ef4efefc7a93c92422a75d98a0339d10589035 (diff) |
Extract hook path generation into a function
This commit extracts the hook path generation into a function.
Extracting a function will later make it easier in tests to assert
we have the correct path when we add the hook path to the transaction's
snapshot.
While at it, update the parent directory to be synced with the
recently introduced helper designed for it.
-rw-r--r-- | internal/gitaly/transaction_manager.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/internal/gitaly/transaction_manager.go b/internal/gitaly/transaction_manager.go index 7caf6148d..1e446ec57 100644 --- a/internal/gitaly/transaction_manager.go +++ b/internal/gitaly/transaction_manager.go @@ -1146,10 +1146,7 @@ func (mgr *TransactionManager) applyCustomHooks(ctx context.Context, logIndex Lo return nil } - syncer := safe.NewSyncer() - - hooksPath := filepath.Join("wal", "hooks") - targetDirectory := filepath.Join(mgr.repositoryPath, hooksPath, logIndex.String()) + targetDirectory := hookPathForLogIndex(mgr.repositoryPath, logIndex) if err := os.Mkdir(targetDirectory, fs.ModePerm); err != nil { // The target directory may exist if we previously tried to extract the // hooks there. TAR overwrites existing files and the hooks files are @@ -1163,19 +1160,26 @@ func (mgr *TransactionManager) applyCustomHooks(ctx context.Context, logIndex Lo return fmt.Errorf("extract hooks: %w", err) } + syncer := safe.NewSyncer() // TAR doesn't sync the extracted files so do it manually here. if err := syncer.SyncRecursive(targetDirectory); err != nil { return fmt.Errorf("sync hooks: %w", err) } // Sync the parent directory as well. - if err := syncer.Sync(filepath.Join(mgr.repositoryPath, hooksPath)); err != nil { + if err := syncer.SyncParent(targetDirectory); err != nil { return fmt.Errorf("sync hook directory: %w", err) } return nil } +// hookPathForLogIndex returns the filesystem paths where the hooks for the +// given log index are stored. +func hookPathForLogIndex(repositoryPath string, logIndex LogIndex) string { + return filepath.Join(repositoryPath, "wal", "hooks", logIndex.String()) +} + // deleteLogEntry deletes the log entry at the given index from the log. func (mgr *TransactionManager) deleteLogEntry(index LogIndex) error { return mgr.deleteKey(keyLogEntry(mgr.relativePath, index)) |