From cd68d64aed4de4b9f9cfd21f2a81bd15c14f3e77 Mon Sep 17 00:00:00 2001 From: Jay Young <60842691+JayYoung2021@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:23:16 +0100 Subject: [PATCH] Update getNewName in comm.go Add check of over-long filename and corresponding error throw. Add output of filename that cannot be assigned a new filename. --- trzsz/comm.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/trzsz/comm.go b/trzsz/comm.go index 7f8df0e..f4f0f18 100644 --- a/trzsz/comm.go +++ b/trzsz/comm.go @@ -433,6 +433,11 @@ func checkDuplicateNames(sourceFiles []*sourceFile) error { } func getNewName(path, name string) (string, error) { + const maxNameLen = 255 + if len(name) > maxNameLen { + return "", simpleTrzszError("File name too long: %s", name) + } + if _, err := os.Stat(filepath.Join(path, name)); os.IsNotExist(err) { return name, nil } @@ -442,7 +447,7 @@ func getNewName(path, name string) (string, error) { return newName, nil } } - return "", simpleTrzszError("Fail to assign new file name") + return "", simpleTrzszError("Fail to assign new file name to %s", name) } type tmuxModeType int