-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkFiles.go
99 lines (78 loc) · 2.38 KB
/
checkFiles.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cmd
import (
"github.com/paulmatencio/s3c/gLog"
"github.com/paulmatencio/s3c/st33/utils"
"github.com/paulmatencio/s3c/utils"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strconv"
)
// readConvalCmd represents the readConval command
var (
idir string
checkFilesCmd = &cobra.Command{
Use: "chkFiles",
Short: "Command to check if all content of a given st33 file has been written to a folder",
Long: `Command to check if all the Tiff images and Blobs of a given st33 data file have been written to a folder`,
Run: func(cmd *cobra.Command, args []string) {
checkFiles(cmd,args)
},
}
)
func initCfFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&ifile,"ifile","i","","the corresponding control file that was used to migrate the data file")
cmd.Flags().StringVarP(&idir,"idir","I","","the name of the folder you would like to check against a given data file")
// cmd.Flags().StringVarP(&odir,"ofile","o","","output file")
}
func init() {
RootCmd.AddCommand(checkFilesCmd)
initCfFlags(checkFilesCmd)
}
func checkFiles(cmd *cobra.Command, args []string) {
var (
pages,w int=0,0
p int
)
if len(ifile) == 0 {
gLog.Info.Printf("%s",missingInputFile)
return
}
if len(idir) == 0 {
gLog.Info.Printf("%s",missingInputFolder)
return
}
if c,err:= st33.BuildConvalArray(ifile); err == nil {
for k, v := range *c {
key := utils.Reverse(v.PxiId)
metafile := filepath.Join(idir,key+".1.md")
if _, err := os.Stat(metafile); err == nil {
if usermd,err := utils.ReadUsermd(metafile); err != nil {
gLog.Error.Printf("Index %d - Error %v reading meta data file %s for key: %s&/%s",k,err,metafile,v.PxiId, key)
} else {
if pg,ok := usermd["Pages"];ok {
p,_ = strconv.Atoi(pg)
vp := int(v.Pages)
if vp != 0 && p != vp {
gLog.Warning.Printf("Index %d - Conval Key %s - S3 Key %s - Conval pages %d != folder pages %d",k, v.PxiId,key ,v.Pages,p)
w ++
} else {
gLog.Trace.Printf("checking pages number of key %s %d %d ",key,p,v.Pages)
}
} else {
gLog.Trace.Println(usermd)
}
}
pages += p
} else {
gLog.Error.Printf("Index: %d - Error %v while checking the metadata for key: %s/%s",k, err,v.PxiId,key)
w++
}
}
if w == 0 {
gLog.Info.Printf("%d documents, %d pages have been migrated without error",len(*c),pages)
}
} else {
gLog.Error.Println(err)
}
}