From 70caca9ca036828995cc9200e6b4d1b09993a301 Mon Sep 17 00:00:00 2001 From: Mirror Date: Mon, 22 Feb 2021 22:30:34 +0300 Subject: [PATCH] Try to not overwrite existing files --- pixiv/downloader.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pixiv/downloader.go b/pixiv/downloader.go index d2ac912..356979b 100644 --- a/pixiv/downloader.go +++ b/pixiv/downloader.go @@ -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