fix: less failure, more trying to push forward
This commit is contained in:
parent
f629e4d962
commit
8ede2b2f8d
BIN
distribusi
BIN
distribusi
Binary file not shown.
@ -229,7 +229,7 @@ func distribusify(c *cli.Context, root string, ignore []string) error {
|
|||||||
if err := filepath.Walk(root, func(fpath string, finfo os.FileInfo, err error) error {
|
if err := filepath.Walk(root, func(fpath string, finfo os.FileInfo, err error) error {
|
||||||
|
|
||||||
if skip := shouldSkip(c, fpath, ignore); skip {
|
if skip := shouldSkip(c, fpath, ignore); skip {
|
||||||
return filepath.SkipDir
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var html []string
|
var html []string
|
||||||
@ -245,11 +245,8 @@ func distribusify(c *cli.Context, root string, ignore []string) error {
|
|||||||
|
|
||||||
contents, err := ioutil.ReadDir(absPath)
|
contents, err := ioutil.ReadDir(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "permission denied") {
|
logrus.Debugf("unable to read %s", absPath)
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, content := range contents {
|
for _, content := range contents {
|
||||||
@ -259,10 +256,11 @@ func distribusify(c *cli.Context, root string, ignore []string) error {
|
|||||||
if content.Name() == "index.html" {
|
if content.Name() == "index.html" {
|
||||||
file, err := os.ReadFile(path.Join(absPath, content.Name()))
|
file, err := os.ReadFile(path.Join(absPath, content.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return filepath.SkipDir
|
logrus.Debugf("unable to read %s, skipping", content.Name())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if strings.Contains(string(file), generatedInDistribusi) {
|
if strings.Contains(string(file), generatedInDistribusi) {
|
||||||
return filepath.SkipDir
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files = append(files, path.Join(absPath, content.Name()))
|
files = append(files, path.Join(absPath, content.Name()))
|
||||||
@ -309,24 +307,28 @@ func distribusify(c *cli.Context, root string, ignore []string) error {
|
|||||||
|
|
||||||
mtype, err := getMtype(file)
|
mtype, err := getMtype(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logrus.Debugf("failed to read mimetype of %s", file)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
unknown, href, err := getHref(c, file, mtype)
|
unknown, href, err := getHref(c, file, mtype)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logrus.Debugf("failed to generate href for %s", file)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
div, err := mkDiv(c, mtype, href, fname, unknown)
|
div, err := mkDiv(c, mtype, href, fname, unknown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logrus.Debugf("failed to generate div for %s", file)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
html = append(html, div)
|
html = append(html, div)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writeIndex(absPath, html, c.String("css")); err != nil {
|
if err := writeIndex(absPath, html, c.String("css")); err != nil {
|
||||||
return err
|
logrus.Debugf("unable to generated %s, skipping", path.Join(absPath, "index.html"))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
allDirs = append(allDirs, strings.Join(dirs, " "))
|
allDirs = append(allDirs, strings.Join(dirs, " "))
|
||||||
@ -377,7 +379,7 @@ func getMtype(fpath string) (string, error) {
|
|||||||
func genThumb(c *cli.Context, fpath, caption string) (string, error) {
|
func genThumb(c *cli.Context, fpath, caption string) (string, error) {
|
||||||
knownFailureExts := []string{".ico", ".svg", ".xcf"}
|
knownFailureExts := []string{".ico", ".svg", ".xcf"}
|
||||||
if sliceContains(knownFailureExts, filepath.Ext(fpath)) {
|
if sliceContains(knownFailureExts, filepath.Ext(fpath)) {
|
||||||
return "", nil
|
return "", fmt.Errorf("unable to generate thumbnail for %s", fpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
imgSrc, err := imaging.Open(fpath, imaging.AutoOrientation(true))
|
imgSrc, err := imaging.Open(fpath, imaging.AutoOrientation(true))
|
||||||
@ -557,7 +559,7 @@ func writeIndex(fpath string, html []string, styles string) error {
|
|||||||
if _, err := os.Stat(absPath); !os.IsNotExist(err) {
|
if _, err := os.Stat(absPath); !os.IsNotExist(err) {
|
||||||
contents, err := os.ReadFile(absPath)
|
contents, err := os.ReadFile(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
body = fmt.Sprintf(htmlBody, generatedInDistribusi, contents, strings.Join(html, "\n"))
|
body = fmt.Sprintf(htmlBody, generatedInDistribusi, contents, strings.Join(html, "\n"))
|
||||||
@ -570,20 +572,24 @@ func writeIndex(fpath string, html []string, styles string) error {
|
|||||||
if _, err := os.Stat(HTMLPath); err != nil {
|
if _, err := os.Stat(HTMLPath); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil {
|
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil {
|
||||||
return err
|
logrus.Debugf("unable to write %s, skipping", HTMLPath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return err
|
logrus.Debugf("unable to read %s, skipping", HTMLPath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file, err := os.ReadFile(HTMLPath)
|
file, err := os.ReadFile(HTMLPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logrus.Debugf("unable to read %s, skipping", HTMLPath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(string(file), generatedInDistribusi) {
|
if strings.Contains(string(file), generatedInDistribusi) {
|
||||||
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil {
|
if err := ioutil.WriteFile(HTMLPath, contents, 0644); err != nil {
|
||||||
return err
|
logrus.Debugf("unable to write %s, skipping", HTMLPath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user