Try to not overwrite existing files

This commit is contained in:
Mirror 2021-02-22 22:30:34 +03:00
parent b3ca71d477
commit 70caca9ca0
1 changed files with 17 additions and 12 deletions

View File

@ -51,21 +51,26 @@ func (p *Pixiv) downloadIllust(i Illust) (err error) {
if err != nil {
return err
}
outfile, err := os.Create(file.directory + file.filename)
if err != nil {
return err
}
defer outfile.Close()
//log.Printf("Downloading %s to %s", file.url, outfile.Name())
err = p.downloadTo(file.url, outfile)
if err != nil {
return err
}
if p.setxattr {
err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(i.TagsString()), 0)
if _, err = os.Stat(file.directory + file.filename); os.IsNotExist(err) {
outfile, err := os.Create(file.directory + file.filename)
if err != nil {
return err
}
defer outfile.Close()
//log.Printf("Downloading %s to %s", file.url, outfile.Name())
err = p.downloadTo(file.url, outfile)
if err != nil {
return err
}
if p.setxattr {
err = syscall.Setxattr(outfile.Name(), "user.xdg.tags", []byte(i.TagsString()), 0)
if err != nil {
return err
}
}
} else {
err = nil
continue
}
}
return