Move diff struct to its own file (#175)

This commit is contained in:
Pieter Noordhuis 2023-01-24 11:06:14 +01:00 committed by GitHub
parent 015a2bf9bb
commit c777a703cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 23 deletions

29
libs/sync/diff.go Normal file
View File

@ -0,0 +1,29 @@
package sync
import (
"fmt"
"strings"
)
type diff struct {
put []string
delete []string
}
func (d diff) IsEmpty() bool {
return len(d.put) == 0 && len(d.delete) == 0
}
func (d diff) String() string {
if d.IsEmpty() {
return "no changes"
}
var changes []string
if len(d.put) > 0 {
changes = append(changes, fmt.Sprintf("PUT: %s", strings.Join(d.put, ", ")))
}
if len(d.delete) > 0 {
changes = append(changes, fmt.Sprintf("DELETE: %s", strings.Join(d.delete, ", ")))
}
return strings.Join(changes, ", ")
}

View File

@ -66,11 +66,6 @@ type Snapshot struct {
RemoteToLocalNames map[string]string `json:"remote_to_local_names"`
}
type diff struct {
put []string
delete []string
}
const syncSnapshotDirName = "sync-snapshots"
func GetFileName(host, remotePath string) string {
@ -170,24 +165,6 @@ func loadOrNewSnapshot(opts *SyncOptions) (*Snapshot, error) {
return snapshot, nil
}
func (d diff) IsEmpty() bool {
return len(d.put) == 0 && len(d.delete) == 0
}
func (d diff) String() string {
if d.IsEmpty() {
return "no changes"
}
var changes []string
if len(d.put) > 0 {
changes = append(changes, fmt.Sprintf("PUT: %s", strings.Join(d.put, ", ")))
}
if len(d.delete) > 0 {
changes = append(changes, fmt.Sprintf("DELETE: %s", strings.Join(d.delete, ", ")))
}
return strings.Join(changes, ", ")
}
func getNotebookDetails(path string) (isNotebook bool, typeOfNotebook string, err error) {
isNotebook = false
typeOfNotebook = ""