Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obscure behavior when dealing with name clashes #134

Closed
stefanos82 opened this issue Sep 24, 2021 · 1 comment
Closed

Obscure behavior when dealing with name clashes #134

stefanos82 opened this issue Sep 24, 2021 · 1 comment
Labels

Comments

@stefanos82
Copy link
Contributor

While I was testing content for #133, I have discovered what in my humble opinion can be considered a very VERY dangerous behavior in generated code.

I have a tmp.nelua located in /home/stefanos/code/nelua/ and decided to create another tmp.nelua, but this new file located in /home/stefanos/tmp/.

The contents of /home/stefanos/code/nelua/tmp.nelua were obviously replaced by contents of /home/stefanos/tmp/tmp.nelua, so was my generated executable.

What would happen if I had original tmp executable running during the compilation of the newly created tmp?

Should not it better to generate name that consists of the entire path, plus the file name instead?

E.g.: /home/stefanos/code/nelua/tmp.nelua should become in /home/stefanos/.cache/ something like home_stefanos_code_nelua_tmp.c; this could reduce the chances to have a conflict.

@edubart
Copy link
Owner

edubart commented Sep 24, 2021

What would happen if I had original tmp executable running during the compilation of the newly created tmp?

On Linux this would work fine, as Linux allows you to replace binaries that are being run, on Windows this would give a compile error, because you cannot replace running files.

On Linux this is really issue only if you try to compiler/run both files at the same time, in that situation you will may have compile errors, or run different application that you expected, this have happened with me before

I don't think it's that dangerous, this is a detail how the compiler works. If you want to avoid that you can simple use the old behavior of using nelua_cache directory instead of ~/.cache, by changing the cache_dir variable in your neluacfg.lua, you could also configure .neluacfg.lua per project basis, so you use different cache for different projects. I will state this is the official workaround.

The behavior will not change, renaming files to full path have other issues that I won't to avoid, like the file name being too long, on Windows a file path is limited to 260 characters. Also would make my life harder to locate generated files when developing Nelua (and would also for others).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants