Skip to content

Commit

Permalink
refactor: remove dependency on copy
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Aug 24, 2024
1 parent 2f63c1a commit 1c2c4e0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/barelyhuman/go v0.2.2-0.20230713173609-2ee88bb52634
github.com/cjoudrey/gluahttp v0.0.0-20201111170219-25003d9adfa9
github.com/joho/godotenv v1.5.1
github.com/otiai10/copy v1.9.0
github.com/vadv/gopher-lua-libs v0.4.1
github.com/yuin/goldmark v1.5.4
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594
Expand All @@ -19,6 +18,5 @@ require (
require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/montanaflynn/stats v0.6.3/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4=
github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -131,9 +124,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956 h1:XeJjHH1KiLpKGb6lvMiksZ9l0fVUh+AmGcm0nOMEBOY=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
46 changes: 43 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
ghttp "github.com/cjoudrey/gluahttp"

"github.com/barelyhuman/go/color"
cp "github.com/otiai10/copy"

stringsLib "github.com/vadv/gopher-lua-libs/strings"

Expand Down Expand Up @@ -127,7 +126,7 @@ func (al *Alvu) CopyPublic() {
// copy public to out
_, err := os.Stat(al.publicPath)
if err == nil {
err = cp.Copy(al.publicPath, outPath)
err = copyDir(al.publicPath, outPath)
if err != nil {
bail(err)
}
Expand Down Expand Up @@ -888,7 +887,7 @@ func normalizeFilePath(path string) string {
return path + ".html"
}

func notFoundHandler(w http.ResponseWriter, r *http.Request) {
func notFoundHandler(w http.ResponseWriter, _ *http.Request) {
if notFoundPageExists {
compiledNotFoundFile := filepath.Join(outPath, "404.html")
notFoundFile, err := os.ReadFile(compiledNotFoundFile)
Expand Down Expand Up @@ -1041,3 +1040,44 @@ func _injectLiveReload(layoutHTML *string) string {
});
</script>`
}

// Recursively copy files from a directory to
// another directory.
// The files copied are overwritten on the dest
func copyDir(src string, dest string) error {
err := os.MkdirAll(dest, os.ModePerm)
if err != nil {
return err
}

dirEntries, err := os.ReadDir(src)
if err != nil {
return err
}

for _, s := range dirEntries {
if s.IsDir() {
if err := os.MkdirAll(filepath.Join(dest, s.Name()), os.ModePerm); err != nil {
return err
}
err := copyDir(path.Join(src, s.Name()), filepath.Join(dest, s.Name()))
if err != nil {
return err
}
} else {
dest, err := os.OpenFile(filepath.Join(dest, s.Name()), os.O_CREATE|os.O_WRONLY, os.ModePerm)
if err != nil {
return err
}
src, err := os.OpenFile(filepath.Join(src, s.Name()), os.O_RDONLY, os.ModePerm)
if err != nil {
return err
}
_, err = io.Copy(dest, src)
if err != nil {
return err
}
}
}
return nil
}

0 comments on commit 1c2c4e0

Please sign in to comment.