Skip to content

Commit

Permalink
fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
scrouthtv committed May 1, 2021
1 parent 0585c58 commit ddf9981
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
)

// Load reads and parses the first config that can be found.
func Load() ([]string, error) {
var kvs []string
configPath, err := findConfigFile()
Expand Down
31 changes: 21 additions & 10 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strconv"
"fmt"
)

var buffersize uint = 32768
Expand Down Expand Up @@ -39,6 +40,8 @@ func copyLoop() {
filepath.Base(sourcePath))

filesLock.Unlock()

os.Remove(destPath)
copyFilePath(sourcePath, destPath)
} else if i < len(fileOrder) {

Expand All @@ -57,19 +60,26 @@ func copyLoop() {

// check if file already exists and we even care about that:
var doCopy bool = true
if onExistingFile != 1 {
stat, err := os.Lstat(destPath)
if err == nil && stat != nil {
stat, err := os.Lstat(destPath)
if err == nil && stat != nil {
// file exists
switch onExistingFile {
case Skip:
doCopy = false
case Overwrite:
os.Remove(destPath)
case Ask:
// save it to the conflicts:
filesLock.Lock()
piledConflicts = append(piledConflicts, i)
filesLock.Unlock()
doCopy = false
default:
// better safe than sorry
doCopy = false
// file exists
if onExistingFile == 2 {
// save it to the conflicts:
filesLock.Lock()
piledConflicts = append(piledConflicts, i)
filesLock.Unlock()
}
}
}

if doCopy {
copyFilePath(sourcePath, destPath)
doneAmount += 1
Expand Down Expand Up @@ -108,6 +118,7 @@ func copyLoop() {
* dest will be created as a link that links to that file as well.
*/
func copyFilePath(sourcePath string, destPath string) {
fmt.Printf("Copying %s to %s\n\n\n\n\n\n\n\n\n", sourcePath, destPath)
var err error
if doReflinks > 0 {
err = reflink(sourcePath, destPath, &doneSize)
Expand Down
15 changes: 13 additions & 2 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ var doReflinks uint8 = 0

var progressLSColors bool = false

// readConfig checks if the config should be read.
func readConfig() bool {
for _, arg := range os.Args {
if arg == "--" {
return false
} else if arg == "--no-config" {
return true
}
}

return false
}

func parseKeyValue(key string, value string) {
// Trim away spaces and tabs:
key = strings.ToLower(strings.Trim(key, " \t'\""))
Expand Down Expand Up @@ -167,8 +180,6 @@ func parseFlag(prefix string, flag string) {
onExistingFile = Overwrite
case "i", "interactive":
onExistingFile = Ask
case "no-config":
doReadConfig = false
case "color":
color.Init(true)
case "reflink":
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"sync"
"fmt"
"time"
)

Expand Down Expand Up @@ -51,8 +52,6 @@ const (
ModeRemove
)

var doReadConfig bool = true

// Maybe these are too small:
// uint64 goes up to 18446744073709551615
// or 2097152 TB
Expand All @@ -63,8 +62,8 @@ func main() {
var err error

color.Init(color.AutoColors())
parseArgs()
if doReadConfig {

if readConfig() {
var kvs []string
kvs, err = config.Load()
if err == nil {
Expand All @@ -75,6 +74,7 @@ func main() {
warnConfig(err)
}
}
parseArgs()

if verbose >= VerbInfo {
printVersion()
Expand Down Expand Up @@ -122,6 +122,7 @@ func main() {
} else {
// if there is more than one source, we want to copy the files
// into the target directory:
fmt.Println("ups:", unsearchedPaths)
stat, err := os.Stat(targetBase)
if os.IsNotExist(err) {
os.MkdirAll(targetBase, 0o755)
Expand Down
2 changes: 1 addition & 1 deletion ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func errEmptySource() {

func errTargetNoDir(file string) {
fmt.Print(color.FGColors.Red)
fmt.Print(file, "is not a directory.")
fmt.Print(file, " is not a directory.")
fmt.Println(color.Text.Reset)
os.Exit(2)
}
Expand Down

0 comments on commit ddf9981

Please sign in to comment.