mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Tweak cmd/wuffsfmt/main.go
This commit is contained in:
1 parent
b37e55f4a5
commit
097e59853d
1 file changed
+6
-8
@@ -97,12 +97,12 @@ func isWuffsFile(info os.FileInfo) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func walk(filename string, info os.FileInfo, err error) error {
|
func walk(filename string, info os.FileInfo, err error) error {
|
||||||
if err == nil && isWuffsFile(info) {
|
if (err == nil) && isWuffsFile(info) {
|
||||||
err = do(nil, filename)
|
err = do(nil, filename)
|
||||||
}
|
}
|
||||||
// Don't complain if a file was deleted in the meantime (i.e. the directory
|
// Don't complain if a file was deleted in the meantime (i.e. the directory
|
||||||
// changed concurrently while running wuffsfmt).
|
// changed concurrently while running this program).
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if (err != nil) && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -158,16 +158,14 @@ func do(r io.Reader, filename string) error {
|
|||||||
const chmodSupported = runtime.GOOS != "windows"
|
const chmodSupported = runtime.GOOS != "windows"
|
||||||
|
|
||||||
func writeFile(filename string, b []byte) error {
|
func writeFile(filename string, b []byte) error {
|
||||||
info, err := os.Stat(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
|
f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if chmodSupported {
|
if chmodSupported {
|
||||||
f.Chmod(info.Mode().Perm())
|
if info, err := os.Stat(filename); err == nil {
|
||||||
|
f.Chmod(info.Mode().Perm())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, werr := f.Write(b)
|
_, werr := f.Write(b)
|
||||||
cerr := f.Close()
|
cerr := f.Close()
|
||||||
|
|||||||
Reference in new issue
Block a user