-
Notifications
You must be signed in to change notification settings - Fork 2
/
status.go
37 lines (30 loc) · 895 Bytes
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package sync
import (
"os"
"strconv"
"github.com/quic-s/quics-client/pkg/db/badger"
)
// @URL /api/v1/sync/status
// ex) ShowStatus("/home/rootDir/text.txt)"
func ShowStatus(filepath string) (string, error) {
pathInfo, err := os.Stat(filepath)
if err != nil {
return "", err
}
if pathInfo.IsDir() {
return "", nil
}
if !badger.IsSyncMetadataExisted(filepath) {
return "", nil
}
value := badger.GetSyncMetadata(filepath)
result := "\n\n=== Status ===\n"
result += "path : " + filepath + "\n"
result += "LastUpdateTimestamp : " + strconv.Itoa(int(value.LastUpdateTimestamp)) + "\n"
result += "LastUpdateHash : " + value.LastUpdateHash + "\n"
result += "---------------\n"
result += "LastSyncTimestamp : " + strconv.Itoa(int(value.LastSyncTimestamp)) + "\n"
result += "LastSyncHash : " + value.LastSyncHash + "\n"
result += "===============\n"
return result, nil
}