parent
0e3910652a
commit
5d1136abfe
20
eval.go
20
eval.go
@ -1116,12 +1116,16 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
log.Printf("getting current directory: %s", err)
|
log.Printf("getting current directory: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
oldPathTo := filepath.Join(wd, curr.Name())
|
|
||||||
newPathTo := filepath.Join(wd, s)
|
oldPath := filepath.Join(wd, curr.Name())
|
||||||
if oldPathTo == newPathTo {
|
newPath := filepath.Join(wd, s)
|
||||||
|
|
||||||
|
if oldPath == newPath {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.renameCache = []string{oldPathTo, newPathTo}
|
|
||||||
|
app.nav.renameOldPath = oldPath
|
||||||
|
app.nav.renameNewPath = newPath
|
||||||
|
|
||||||
if dir, _ := filepath.Split(s); dir != "" {
|
if dir, _ := filepath.Split(s); dir != "" {
|
||||||
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil {
|
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil {
|
||||||
@ -1130,7 +1134,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(newPathTo); err == nil { // file exists
|
oldStat, err := os.Stat(oldPath)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if newStat, err := os.Stat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {
|
||||||
app.ui.cmdPrefix = "replace " + s + "?[y/N]"
|
app.ui.cmdPrefix = "replace " + s + "?[y/N]"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
15
nav.go
15
nav.go
@ -270,7 +270,8 @@ type nav struct {
|
|||||||
regCache map[string]*reg
|
regCache map[string]*reg
|
||||||
saves map[string]bool
|
saves map[string]bool
|
||||||
marks map[string]string
|
marks map[string]string
|
||||||
renameCache []string
|
renameOldPath string
|
||||||
|
renameNewPath string
|
||||||
selections map[string]int
|
selections map[string]int
|
||||||
selectionInd int
|
selectionInd int
|
||||||
height int
|
height int
|
||||||
@ -359,7 +360,6 @@ func newNav(height int) *nav {
|
|||||||
regCache: make(map[string]*reg),
|
regCache: make(map[string]*reg),
|
||||||
saves: make(map[string]bool),
|
saves: make(map[string]bool),
|
||||||
marks: make(map[string]string),
|
marks: make(map[string]string),
|
||||||
renameCache: make([]string, 2),
|
|
||||||
selections: make(map[string]int),
|
selections: make(map[string]int),
|
||||||
selectionInd: 0,
|
selectionInd: 0,
|
||||||
height: height,
|
height: height,
|
||||||
@ -824,17 +824,12 @@ func (nav *nav) del(ui *ui) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) rename() error {
|
func (nav *nav) rename() error {
|
||||||
oldPath := nav.renameCache[0]
|
oldPath := nav.renameOldPath
|
||||||
newPath := nav.renameCache[1]
|
newPath := nav.renameNewPath
|
||||||
|
|
||||||
dir, _ := filepath.Split(newPath)
|
dir, _ := filepath.Split(newPath)
|
||||||
os.MkdirAll(dir, os.ModePerm)
|
os.MkdirAll(dir, os.ModePerm)
|
||||||
|
|
||||||
if _, err := os.Stat(newPath); err == nil { // file exists
|
|
||||||
if err := os.Remove(newPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Rename(oldPath, newPath); err != nil {
|
if err := os.Rename(oldPath, newPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user