X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=main.go;h=eb67c8069fa2534b645368e1504b8b6963bb7853;hb=HEAD;hp=c579a0f6ec935414ff18815fa3eaf0aea62ebcb1;hpb=6dce71355599d4caf8267f6f02520037480f7ba3;p=goredo.git diff --git a/main.go b/main.go index c579a0f..eb67c80 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,17 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2023 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 Sergey Matveev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . package main @@ -21,9 +19,11 @@ import ( "bufio" "bytes" "encoding/hex" + "errors" "flag" "fmt" "io" + "io/fs" "log" "os" "os/signal" @@ -93,12 +93,23 @@ func main() { var symlinks *bool cmdName := CmdName() - if cmdName == "goredo" { + if cmdName == CmdNameGoredo { symlinks = flag.Bool("symlinks", false, "create necessary symlinks in current directory") } flag.Usage = func() { usage(os.Args[0]) } - flag.Parse() + + BuildUUIDStr := os.Getenv(EnvBuildUUID) + IsTopRedo = BuildUUIDStr == "" + + var args []string + if IsTopRedo { + flag.Parse() + args = flag.Args() + } else { + args = os.Args[1:] + } + if *warranty { fmt.Println(Warranty) return @@ -187,7 +198,7 @@ func main() { LogLock = os.Getenv(EnvLogLock) == "1" LogJS = os.Getenv(EnvLogJS) == "1" if Debug || os.Getenv(EnvLogPid) == "1" { - MyPid = os.Getpid() + MyPID = os.Getpid() } var traced bool if flagTraceAll != nil && *flagTraceAll { @@ -279,13 +290,12 @@ func main() { fdDep = mustParseFd(v, EnvDepFd) } - tgts := make([]*Tgt, 0, len(flag.Args())) - for _, arg := range flag.Args() { + tgts := make([]*Tgt, 0, len(args)) + for _, arg := range args { tgts = append(tgts, NewTgt(arg)) } tgtsWasEmpty := len(tgts) == 0 - if BuildUUIDStr := os.Getenv(EnvBuildUUID); BuildUUIDStr == "" { - IsTopRedo = true + if BuildUUIDStr == "" { BuildUUID = uuid.New() if tgtsWasEmpty { tgts = append(tgts, NewTgt("all")) @@ -382,9 +392,13 @@ func main() { var dos []string dos, err = whichdo(tgts[0]) if err != nil { - break + if errors.Is(err, fs.ErrNotExist) { + err = nil + ok = false + } else { + break + } } - sort.Strings(dos) for _, do := range dos { fmt.Println(do) } @@ -497,7 +511,7 @@ func main() { DepFixHashCache = make(map[string]Hash) err = depFix(Cwd) case CmdNameRedoInode: - var inode Inode + var inode *Inode for _, tgt := range tgts { inode, err = inodeFromFileByPath(tgt.a) if err != nil { @@ -532,6 +546,7 @@ func main() { } var typ byte var chunk []byte + var inode Inode for len(data) > 0 { typ, chunk, data, _ = chunkRead(data) switch typ { @@ -551,7 +566,7 @@ func main() { }...) case DepTypeIfchange: name := string(chunk[InodeLen+HashLen:]) - meta := string(chunk[:InodeLen+HashLen]) + meta := chunk[:InodeLen+HashLen] fields := []recfile.Field{ {Name: "Type", Value: "ifchange"}, {Name: "Target", Value: name}, @@ -559,9 +574,10 @@ func main() { fields = append(fields, recfile.Field{ Name: "Hash", Value: Hash(meta[InodeLen:]).String(), }) - fields = append(fields, Inode(meta[:InodeLen]).RecfileFields()...) + inode = Inode(meta[:][:InodeLen]) + fields = append(fields, inode.RecfileFields()...) err = recfileWrite(w, fields...) - case DepTypeIfchangeDummy: + case DepTypeIfchangeNonex: err = recfileWrite(w, []recfile.Field{ {Name: "Type", Value: "ifchange"}, {Name: "Target", Value: string(chunk)},