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

temp file not working on Windows (Git bash) #20

Closed
alisonatwork opened this issue Dec 4, 2023 · 8 comments
Closed

temp file not working on Windows (Git bash) #20

alisonatwork opened this issue Dec 4, 2023 · 8 comments
Assignees
Milestone

Comments

@alisonatwork
Copy link

Trying to run the tests of gron.awk fails in Git bash (git version 2.43.0.windows.1, bash 5.2.21(1)-release).

$ ./makesure
  goal 'soft_folder_created' ...
  goal 'soft_folder_created' took 0.05 s
  goal 'fhtagn_installed' ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3034  100  3034    0     0   6281      0 --:--:-- --:--:-- --:--:--  6281
  goal 'fhtagn_installed' took 0.633 s
  goal 'debug' ...
GNU Awk 5.0.0, API: 2.0 (GNU MPFR 4.2.1, GNU MP 6.3.0)
GNU bash, version 5.2.21(1)-release (x86_64-pc-msys)
  goal 'debug' took 0.101 s
  goal 'prepared4tests' [empty].
  goal 'tests.basic.tush' ...
sh: line 1: /dev/shm/fhtagn.765879820.932.out: Permission denied
error reading file: /dev/shm/fhtagn.765879820.932.out
!!! TESTS FAILED !!! : tests.basic.tush
  goal 'tests.basic.tush' failed
  goal 'tests.basic.tush' took 0.143 s
  total time 1.011 s
$

I tracked the problem down to this project, which creates temp files in /dev/shm based on the following snippet: [ -d /dev/shm ] && echo /dev/shm || echo /tmp. The problem is that on Git bash this returns okay because the directory has to exist for POSIX reasons, but it seems like you can't write to it. (At least, if I try to touch /dev/shm/foo it fails.)

I am not sure if there is a way to coerce fopens in Cygwin/MINGW to apply a Win32 FILE_ATTRIBUTE_TEMPORARY flag, but it's probably not worth it to investigate. I think the best approach might be to just test that writing to that directory actually works before using it.

Separately, when explicitly setting the temporary directory to /tmp, then makesure fails inside fhtagn itself with a missing wget when trying to download the one true awk. Although probably that would fail even if it used curl because Git bash doesn't have a toolchain, which is why using awk/makesure/etc is appealing in the first place.

@xonixx
Copy link
Owner

xonixx commented Dec 4, 2023

Thank you for the bug report. Looking into it.

@xonixx
Copy link
Owner

xonixx commented Dec 4, 2023

I understand you run it for the gron.awk project. What is strange, it runs fine on Win with Github actions: https://github.com/xonixx/gron.awk/actions/runs/6448782633. And from what I see the versions you use are the same as in Github Actions environment.

Also you do have curl, since in your log we have this output of it:

  goal 'fhtagn_installed' ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3034  100  3034    0     0   6281      0 --:--:-- --:--:-- --:--:--  6281
  goal 'fhtagn_installed' took 0.633 s

This needs some futher investigation.

@alisonatwork
Copy link
Author

alisonatwork commented Dec 4, 2023

Yes, I have curl, but I do not have wget, which is hard-coded without fallback in a couple of places in the fhtagn Makesurefile.

I see the Github action starts a Powershell and then runs bash -e -c './makesure', but I just tried that and it didn't make a difference. However, with Powershell I can also start a console with administrator privileges and there it does work! So it must be a permissions issue writing to the /dev/shm directory. That makes sense, actually, if you translate the path back to C:\Program Files\Git\dev\shm, which is not writable by normal users unless they are running in an elevated console.

I am not sure if there is an easy way to check if the console is running with elevated privileges on Windows other than to try do something and have it fail. Maybe if it's too tricky to implement a check for this into fhtagn for the corner case, it could just be documented that you need to run it as administrator on Git bash?

@xonixx
Copy link
Owner

xonixx commented Dec 4, 2023

Thank you @alisonatwork for the valuable details. Yes, it appears that Github Actions run on root(-like) user.
Yes, it's a bug with fhtagn, it should run fine with regular user. I'll work on a fix.

@AdamantGarth
Copy link

Even without this issue, fhtagn should probably respect the TMPDIR environment variable in case the user needs to customize it. On Windows, it's usually called TEMP or TMP, so worth checking all three.

@xonixx
Copy link
Owner

xonixx commented Dec 8, 2023

Fixed in the main branch. @alisonatwork Could you please retry.

@AdamantGarth thank you for the proposal, now fhtagn respects TMPDIR (if set).

@xonixx xonixx self-assigned this Dec 8, 2023
@xonixx
Copy link
Owner

xonixx commented Dec 10, 2023

Closing as completed. Please feel free to reopen if the issue persists.

@xonixx xonixx closed this as completed Dec 10, 2023
@alisonatwork
Copy link
Author

I just pulled and ran it again on Git bash, the basic tests now pass in fhtagn core. gron.awk I guess is not updated to use the latest version, so the tests still fail there.

Separately, I still have a wget problem, but I will open a new ticket for that.

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

No branches or pull requests

3 participants