waveterm icon indicating copy to clipboard operation
waveterm copied to clipboard

[Bug]: If a folder is soft link, it will be treated as a file and not a folder

Open abgox opened this issue 1 year ago • 9 comments

Current Behavior

  • If a folder is soft link, it will be treated as a file and not a folder. And associated icons, types, etc. are all wrong.

recording

Expected Behavior

They should be correctly recognized as a folder.

Steps To Reproduce

When you use File Preview to browse a file directory, this error occurs whenever a folder in the directory is soft link.

Wave Version

0.10.4

Platform

Windows

OS Version/Distribution

Windows 11

Architecture

x64

Anything else?

No response

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

abgox avatar Jan 08 '25 10:01 abgox

hey are you using cmd's mklink to create symbolic links by any chance?

I reproduced it with 3 shells and only cmd caused the bug image

Jalileh avatar Jan 09 '25 18:01 Jalileh

  • I use the pwsh command New-Item -ItemType SymbolicLink xxx to create the soft link.
  • I think pwsh and cmd may work the same way.

abgox avatar Jan 10 '25 10:01 abgox

  • I use the pwsh command New-Item -ItemType SymbolicLink xxx to create the soft link.
  • I think pwsh and cmd may work the same way.

Noticed more of my folders were also bugged and I don't use CMD.

Doesn't matter if we dont use cmd, other scripts/programs will eventually use it like the .config folder.

Golang os package literally wont return the bits for CMD made symlinks from fileInfo.Mode all it returns is read perm bits.

EDIT: nevermind, fixed it.

Jalileh avatar Jan 10 '25 15:01 Jalileh

closing as we're about to release 0.11. Thank you @Jalileh for fixing this!!

esimkowitz avatar Jan 24 '25 23:01 esimkowitz

  • @esimkowitz @Jalileh

  • Unfortunately, this bug still exists in v0.11.0.

    Image

abgox avatar Jan 27 '25 11:01 abgox

@abgox what utility do you use to make your symlinks? Could you provide reproduction steps?

esimkowitz avatar Jan 27 '25 15:01 esimkowitz

@esimkowitz

Yeah sorry, the bug here is in the dot of the symlink folder name ( .config ) PR bot ironically made it less robust at the cost of my over-engineered approach

 	isFileSymlink := func(filepath string) bool {
		Length := len(filepath) - 1
		maxFileDotExt := 4 // should cover most file extensions
		for i := Length; i >= (Length - maxFileDotExt); i-- {
			if filepath[i] == '.' {
				return true
			}
		}
		return false
	}

Image

isFileSymlink := func(filepath string) bool {
+        if len(filepath) == 0 {
+            return false
+        }
+        return strings.LastIndex(filepath, ".") > strings.LastIndex(filepath, "/")
 }

Image

Jalileh avatar Jan 27 '25 17:01 Jalileh

@abgox what utility do you use to make your symlinks? Could you provide reproduction steps?

  • I use the pwsh command New-Item -ItemType SymbolicLink xxx to create the soft link.

Yeah sorry, the bug here is in the dot of the symlink folder name ( .config ) PR bot ironically made it less robust at the cost of my over-engineered approach

  • That's right, the bug only exists in symlink folders with .

  • As long as the directory name contains . , the bug exists.

    Image

abgox avatar Jan 28 '25 00:01 abgox

fixing this right now and realize the AI refractor doesnt even improve upon my method, windows doesnt even use / for directories it uses \\

this line literally does nothing

return strings.LastIndex(filepath, ".") > strings.LastIndex(filepath, "/"),

I'm going to open a PR and revert back to the one I wrote before and hopefully make it less linear and unreliable so AI dosen't suggest anything worse again. Soz!

Jalileh avatar Jan 28 '25 15:01 Jalileh