Problem with generated symlink by crystal

Hi guys. I am coming to you today because I am facing a problem with the command from FileUtils to make symbolic link.

I noticed, if I run the same command to make a symlink 2 times, it make a symlink inside the directory targeted.

Let me explain:

I have one directory named TEST, located in /home/me/TEST
I want to make a symlink named SYSTEM to the dir TEST

If I run it again, a symlink named SYSTEM appear in my directory TEST. Why ?

require "file_utils"
FileUtils.ln_s("TEST", "SYSTEM")

require "file_utils"
FileUtils.ln_s("TEST", "SYSTEM")

Because basically, I would like if that symlink is already here, it don’t overcreate anything else

I need to fix that in that code:

def makeLink(path : String, targetPath : String, linkType : Symbol)
            begin
                case linkType
                when :hardLink
                    FileUtils.ln(path, targetPath)
                when :symbolicLink
                    FileUtils.ln_s(path, targetPath)
                when :symbolicLinkByOverwrite
                    FileUtils.ln_sf(path, targetPath)
                else
                    Ism.exitProgram
                end
            rescue File::AlreadyExistsError

            rescue error
                Ism.notifyOfMakeLinkError(path, targetPath, error)
                Ism.exitProgram
            end
        end

But I don’t know how to fix that

Then just check if it already exists before creating it?

I thought about that, it’s just. If for example the symlink need to be updated or point to another file ? Just deleting it first ?

I overthink too much I think :crazy_face:

That’s what I would do yea. Easy enough to just delete it if it exists, then create. This would handle both brand new links and updating existing links.