From 9ff62bb39b69c75ee15508a7266d45e15c0608a2 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 25 Apr 2024 20:20:20 +0200 Subject: rename go --- src/e_events.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/e_events.go') diff --git a/src/e_events.go b/src/e_events.go index 60f7db9..21cad94 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -316,14 +316,24 @@ func e_mkdir(data *HardData, ui *HardUI) { } } -func e_rename(data *HardData, ui *HardUI) { - if len(ui.buff) == 0 || - data.litems.curr == nil || data.litems.curr.is_dir() == true { - return +func e_rename(data *HardData, ui *HardUI) error { + tmp := data.litems.curr + + if len(ui.buff) == 0 || tmp == nil || tmp.is_dir() == true || + ui.buff == tmp.Host.Name { + return nil + } + new_host := e_deep_copy_host(data.litems.curr.Host) + new_host.Name = ui.buff + ui.insert_method = INSERT_MOVE + i_insert_host(data, &new_host) + data.litems.del(tmp) + file_path := data.data_dir + tmp.Host.parent.path() + tmp.Host.filename + if err := os.Remove(file_path); err != nil { + c_error_mode("can't remove " + file_path, err, &data.ui) + return err } - data.litems.curr.Host.Name = ui.buff - // ui.insert_method = INSERT_MOVE - // i_insert_host(data, new_host) + return nil } func e_set_drive_keys(data *HardData) { -- cgit v1.2.3