Fix setting the timestamp
This commit is contained in:
parent
11e13c4d3f
commit
c44567a1d8
105
main.go
105
main.go
@ -131,6 +131,59 @@ var (
|
||||
workDir *string = flag.String("work", "/perm/workDir", "working directory for sqlite files")
|
||||
)
|
||||
|
||||
func extractSqlite(file *os.File) error {
|
||||
|
||||
// open sqlite file
|
||||
size, err := file.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
_, err = file.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
zipFile, err := zip.NewReader(file, size)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
// determine names and create destination files
|
||||
sqlite_filename = zipFile.File[0].Name
|
||||
sqlite_br_filename = zipFile.File[0].Name + ".br"
|
||||
|
||||
sqlite_file, err := os.Create(filepath.Join(*workDir, sqlite_filename))
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite_file.Close()
|
||||
|
||||
sqlite_br_file, err := os.Create(filepath.Join(*workDir, sqlite_br_filename))
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite_br_file.Close()
|
||||
|
||||
sqlite, err := zipFile.File[0].Open()
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite.Close()
|
||||
|
||||
// read from zip to file in addition to the brotli encoder below
|
||||
sqlite_reader := io.TeeReader(sqlite, sqlite_file)
|
||||
br := brotli.NewWriterLevel(sqlite_br_file, 5)
|
||||
defer br.Close()
|
||||
log.Printf("starting compression of %s to %s\n", sqlite_filename, sqlite_br_filename)
|
||||
|
||||
// Brotli encodes sqlite file. TeeReader ensures uncompressed copy is also available
|
||||
_, err = io.Copy(br, sqlite_reader)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func download(current time.Time) {
|
||||
current = time.Date(current.Year(), current.Month(), current.Day(), 0, 0, 0, 0, current.Location())
|
||||
u, _ := url.Parse("https://www.comics.org/accounts/login/?next=/download/")
|
||||
@ -219,57 +272,7 @@ func download(current time.Time) {
|
||||
}
|
||||
log.Println("Download Complete")
|
||||
|
||||
// open sqlite file
|
||||
size, err := file.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
_, err = file.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
zipFile, err := zip.NewReader(file, size)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
// determine names and create destination files
|
||||
sqlite_filename = zipFile.File[0].Name
|
||||
sqlite_br_filename = zipFile.File[0].Name + ".br"
|
||||
|
||||
sqlite_file, err := os.Create(filepath.Join(*workDir, sqlite_filename))
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite_file.Close()
|
||||
|
||||
sqlite_br_file, err := os.Create(filepath.Join(*workDir, sqlite_br_filename))
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite_br_file.Close()
|
||||
|
||||
sqlite, err := zipFile.File[0].Open()
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
defer sqlite.Close()
|
||||
|
||||
// read from zip to file in addition to the brotli encoder below
|
||||
sqlite_reader := io.TeeReader(sqlite, sqlite_file)
|
||||
|
||||
br := brotli.NewWriterLevel(sqlite_br_file, 5)
|
||||
defer br.Close()
|
||||
|
||||
log.Printf("starting compression of %s to %s\n", sqlite_filename, sqlite_br_filename)
|
||||
|
||||
// Brotli encodes sqlite file. TeeReader ensures uncompressed copy is also available
|
||||
_, err = io.Copy(br, sqlite_reader)
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
|
||||
err = extractSqlite(file)
|
||||
// rename files to final location
|
||||
err = os.Rename(filepath.Join(*workDir, sqlite_filename), filepath.Join(*destination, sqlite_filename))
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user