Fix setting the timestamp

This commit is contained in:
Timmy Welch 2024-02-24 18:50:25 -08:00
parent 11e13c4d3f
commit c44567a1d8

105
main.go
View File

@ -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 {