Code review from @diamondburned
-
https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/main.go#L36 use return instead -
give this Fatal some context, e.g. log.Fatalln("initramfs:", err)
if err := generateInitfs("initramfs", workDir, kernVer, devinfo); err != nil {
log.Fatal(err)
}
-
https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/main.go#L88 errors' first letters should be lower-cased -
you should make exists(file string)
return an error instead to account for other errors like missing perms ingetBinaryDeps
, you're logging and returning an error, but not sure if there's a point to this -
L204 you could probably defer after the error check and call Close() twice it's fine to do that well, not exactly needed here ,but yeahWell,getBinaryDeps
is recursive, so it could end up with quite a few open fds if I useddefer
-
redundant continue https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/main.go#L477 -
for stripExt, you can probably just split by .
and[0]
-
package misc
should be broken up imo -
UPDATE: (cc) StringSet was removed/replacedStringSet
could be in package set and have type map[string]struct{}; you can even put a constructor there that creates it from a []string if you want -
RelativeSymlinkTargetToDir
seems like a bad function (because it callsChdir
; you can probably usefilepath.Join(dir, symPath)
here, then useAbs()
on it probably move that topackage osutil
along withFreeSpace()
-
you can make a postmarketos-mkinitfs/internal/osutil
-
https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/pkgs/archive/archive.go#L74 move this defer
to after the error check, else this code will panic if the file fails to be opened -
https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/pkgs/archive/archive.go#L82 use _, err := io.Copy(sha256, fd)
instead also you could callsha256
something likeh
orhash
instead andfd
f
-
forgot an error check here https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/pkgs/archive/archive.go#L146 -
for all files, you should write
// Copyright...
package whatever
the new line in-between is important w/ how you're writing it rn, Go will parse those comments as part of the package documentation, not copyright (the Go stdlib does something similar to this; you can look at it for reference)
-
don't use github.com/BurntSushi/toml; it's quite outdated use pelletier's instead: https://pkg.go.dev/github.com/pelletier/go-toml -
also you should probably name fields in DeviceInfo to have the appropriate casing: AppendDTB, Arch, etc. then do
type DeviceInfo struct {
AppendDTB `toml:"deviceinfo_append_dtb"`
}
-
https://gitlab.postmarketos.org/postmarketos/postmarketos-mkinitfs/-/blob/master/pkgs/deviceinfo/deviceinfo.go#L44 redundant Stat; let the DecodeFile handle Open() errors. you can do anNot relevant I think now that I've replaced the file parsing/unmarshalling thing with something else in !4 (merged)os.IsNotExists(err)
if you really want to fix your own error over it