v icon indicating copy to clipboard operation
v copied to clipboard

Simple permission error not gracefully handled?

Open kpeters58 opened this issue 3 years ago • 4 comments

D:\projects\v>v -prod vgetter.v D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file D:\projects\v\vgetter.exe: Permission denied collect2.exe: error: ld returned 1 exit status (Use v -cg to print the entire error message)

builder error: C error. This should never happen.

This is a compiler bug, please report it using v bug file.v.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

D:\projects\v>v version V 0.2.4 524df8d

kpeters58 avatar Jun 22 '22 02:06 kpeters58

This is a Windows-specific problem, and can happen for several reasons, including

  • The file is actually set to read-only.
  • The file is open.
  • The file is on another volume, with CIFS protections.
  • etc., etc.

The first is easily checked. The rest... not so much.

JalonSolov avatar Jun 22 '22 12:06 JalonSolov

I am not suggesting root cause analysis here at all, just an orderly exit with a message along the lines: 'Executable could not be created. (Either in use, read-only or ...)' - just like much of the rest of the world does. I believe that in > 90% of all cases this would be due to the executable being in use, as it was in my case.

kpeters58 avatar Jun 22 '22 14:06 kpeters58

The problem there is that V isn't trying to write the executable - the C compiler is. There is no way for V to handle that.

It could (and should) be done with the native backend, once that it further along.

JalonSolov avatar Jun 22 '22 15:06 JalonSolov

Was about to open a new issue, but just ran into this one. My scenario is slightly different however.

V doctor:

OS: macos, macOS, 12.4, 21F79
Processor: 8 cpus, 64bit, little endian, Apple M1 Pro
CC version: Apple clang version 13.1.6 (clang-1316.0.21.2.5)

getwd: /Users/harensamarasinghe/Downloads
vmodules: /Users/harensamarasinghe/.vmodules
vroot: /opt/local/lib/vlang
vexe: /opt/local/lib/vlang/v
vexe mtime: 2022-07-25 09:58:12
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 f9385f6

Git version: git version 2.36.1
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false
thirdparty/tcc: N/A

What did you do?

sudo v hello.v
v -cg hello.v
println("hi")

sudo means that the owner of the executable is root. When run without sudo, V expectedly is unable to overwrite it. However, it then proceeds to crash.

What did you expect to see?

hi

What did you see instead?

/tmp/v_501/hello.13329014037347262016.tmp.c:2118:4: warning: expression result unused [-Wunused-value]
  (*(int*)_t1.data);
   ^~~~~~~~~~~~~~~
1 warning generated.
ld: can't write output file: /Users/harensamarasinghe/Downloads/hello for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

harens avatar Jul 25 '22 10:07 harens