Skip to content
Snippets Groups Projects
Commit 3b820d58 authored by Sami Hiltunen's avatar Sami Hiltunen
Browse files

Record alternate link operations in handler

Alternate linking operation have so far been recorde in transaction
manager as we didn't have a general API for staging file system
operations in transactions. As we have such an API now, move the
linking operation to be recorded in the handler.

We reuse the logic from the handler in the tests and remove the
custom linking logic.
parent 0497901b
No related branches found
No related tags found
Loading
......@@ -71,6 +71,15 @@ func Link(ctx context.Context, pool, repo *localrepo.Repo, txManager transaction
if tx := storage.ExtractTransaction(ctx); tx != nil {
tx.MarkAlternateUpdated()
alternatesRelativePath, err := filepath.Rel(tx.FS().Root(), altPath)
if err != nil {
return fmt.Errorf("rel alternates file: %w", err)
}
if err := tx.FS().RecordFile(alternatesRelativePath); err != nil {
return fmt.Errorf("record alternates file")
}
}
return removeMemberBitmaps(ctx, pool, repo)
......
......@@ -1176,25 +1176,15 @@ func runTransactionTest(t *testing.T, ctx context.Context, tc transactionTestCas
))
if step.UpdateAlternate.RelativePath != "" {
transaction.MarkAlternateUpdated()
repoPath, err := rewrittenRepo.Path(ctx)
require.NoError(t, err)
alternatesContent, err := filepath.Rel(
filepath.Join(transaction.FS().Root(), transaction.relativePath, "objects"),
filepath.Join(transaction.FS().Root(), step.UpdateAlternate.RelativePath, "objects"),
)
require.NoError(t, err)
require.NoError(t, os.WriteFile(stats.AlternatesFilePath(repoPath), []byte(alternatesContent), fs.ModePerm))
alternates, err := stats.ReadAlternatesFile(repoPath)
require.NoError(t, err)
for _, alternate := range alternates {
require.DirExists(t, filepath.Join(repoPath, "objects", alternate), "alternate must be pointed to a repository: %q", alternate)
}
require.NoError(t, objectpool.Link(
storage.ContextWithTransaction(ctx, transaction),
setup.RepositoryFactory.Build(transaction.RewriteRepository(&gitalypb.Repository{
StorageName: setup.Config.Storages[0].Name,
RelativePath: step.UpdateAlternate.RelativePath,
})),
rewrittenRepo,
nil,
))
}
}
......
......@@ -1118,25 +1118,6 @@ func (mgr *TransactionManager) commit(ctx context.Context, transaction *Transact
return fmt.Errorf("preparing housekeeping: %w", err)
}
if transaction.alternateUpdated {
stagedAlternatesRelativePath := stats.AlternatesFilePath(transaction.relativePath)
stagedAlternatesAbsolutePath := mgr.getAbsolutePath(transaction.snapshot.RelativePath(stagedAlternatesRelativePath))
if _, err := os.Stat(stagedAlternatesAbsolutePath); err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("check alternates existence: %w", err)
}
// Alternates file did not exist, nothing to stage. This was an unlink operation.
} else {
if err := transaction.walEntry.CreateFile(
stagedAlternatesAbsolutePath,
stagedAlternatesRelativePath,
); err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("record alternates update: %w", err)
}
}
}
// If there were objects packed that should be committed, record the packfile's creation.
if transaction.packPrefix != "" {
packDir := filepath.Join(transaction.relativePath, "objects", "pack")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment