mirror of
https://github.com/kopia/kopia.git
synced 2026-01-02 03:27:51 -05:00
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`
- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
interface
Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.
`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).
* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session
* cli: disable maintenance in 'kopia server start'
Server will close the repository before completing.
* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
- used atomic to manage SharedManager.closed
* removed stale example
* linter: fixed spurious failures
Co-authored-by: Julio López <julio+gh@kasten.io>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/fs"
|
|
"github.com/kopia/kopia/internal/diff"
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/snapshot/snapshotfs"
|
|
)
|
|
|
|
var (
|
|
diffCommand = app.Command("diff", "Displays differences between two repository objects (files or directories)").Alias("compare")
|
|
diffFirstObjectPath = diffCommand.Arg("object-path1", "First object/path").Required().String()
|
|
diffSecondObjectPath = diffCommand.Arg("object-path2", "Second object/path").Required().String()
|
|
diffCompareFiles = diffCommand.Flag("files", "Compare files by launching diff command for all pairs of (old,new)").Short('f').Bool()
|
|
diffCommandCommand = diffCommand.Flag("diff-command", "Displays differences between two repository objects (files or directories)").Default(defaultDiffCommand()).Envar("KOPIA_DIFF").String()
|
|
)
|
|
|
|
func runDiffCommand(ctx context.Context, rep repo.Repository) error {
|
|
ent1, err := snapshotfs.FilesystemEntryFromIDWithPath(ctx, rep, *diffFirstObjectPath, false)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "error getting filesystem entry for %v", *diffFirstObjectPath)
|
|
}
|
|
|
|
ent2, err := snapshotfs.FilesystemEntryFromIDWithPath(ctx, rep, *diffSecondObjectPath, false)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "error getting filesystem entry for %v", *diffSecondObjectPath)
|
|
}
|
|
|
|
_, isDir1 := ent1.(fs.Directory)
|
|
_, isDir2 := ent2.(fs.Directory)
|
|
|
|
if isDir1 != isDir2 {
|
|
return errors.New("arguments do diff must both be directories or both non-directories")
|
|
}
|
|
|
|
d, err := diff.NewComparer(os.Stdout)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error creating comparer")
|
|
}
|
|
defer d.Close() //nolint:errcheck
|
|
|
|
if *diffCompareFiles {
|
|
parts := strings.Split(*diffCommandCommand, " ")
|
|
d.DiffCommand = parts[0]
|
|
d.DiffArguments = parts[1:]
|
|
}
|
|
|
|
if isDir1 {
|
|
return d.Compare(ctx, ent1, ent2)
|
|
}
|
|
|
|
return errors.New("comparing files not implemented yet")
|
|
}
|
|
|
|
func defaultDiffCommand() string {
|
|
if isWindows() {
|
|
return "cmp"
|
|
}
|
|
|
|
return "diff -u"
|
|
}
|
|
|
|
func init() {
|
|
diffCommand.Action(repositoryReaderAction(runDiffCommand))
|
|
}
|