I'm not necessarily sure that the subject is clear enough, so I want to be
explicit that I'm talking about files (or I guess potentially directories,
though I've never seen that) generated by the `try_to_bin` function in
winsup/cygwin/syscalls.cc.  Specifically, you can generate one with this
simple bash reproducer:

cp /usr/bin/sleep.exe .
./sleep 1000 &
rm -f ./sleep.exe
kill %1
fg

My questions are (starting at the beginning with what I'm trying to
accomplish, and wandering off into the weeds of the various things I've
tried to do that).

1) is there some mechanism in Cygwin that I'm not seeing to clean up these
files?  So far I've confirmed that their creation does not result in the
recycle bin icon turning from 'empty' to 'full' on the desktop, and that
emptying the recycle bin there (when it doesn't think it's already empty)
does not remove them.

2) assuming there is not, I want to make a script using only things
present in a "base system" to clean them up.  This isn't too horribly
difficult, using bash and find, *if I can assume that all Windows volumes
are rooted at drive letters*.  Once I take into account Windows
folder-mounted volumes, I need to be able to find a list of all volume
roots, in a safe way.  I hacked together a sed script that parses the
output of `mountvol`, but that is clearly not safe (not only did it rely
on a message that is likely translated, but mountvol seems to switch to
ANSI output when it is piped or redirected, and any unicode characters
turn into '_') [1].

I made a C program to do this [2], and that's fine, except I really wanted
to avoid having to ship a new binary.  Is there any way in Cygwin to get
this list?  Maybe this is something that should be added to cygpath?

3) in furtherance of figuring that out, I started grepping around for
FindNextVolumeW and GetVolumePathNamesForVolumeNameW in cygwin, and found
the dos_drive_mappings class in winsup/cygwin/mount.cc.  This is
sort-of exposed via the cygwin_internal function CW_ALLOC_DRIVE_MAP,
though the type itself is not.  As a proof-of-concept hack, I wrote
another C program based on this [3], but I don't think that really helps
anything.

4) while pondering this, I keep coming back to the idea that volume folder
mounts could be exposed via the 'normal' mount interface, such as
`getmntent`, `/proc/self/mounts`, `/proc/self/mountinfo`), as children of
the drive-letter cygdrive mounts.  This would make getting the list of
mounts safely a solved problem(*), and would probably also have the bonus
effect of letting `df` list their free space.  Is there a good reason that
this is not already done (other than SHTDI)?

* I found a bug/limitation here, which I will report in a separate email,
because that doesn't depend on any of this.

5) in addition, I ported the C example programs to python ctypes, and
factored out to a small module [4], but that also doesn't really help,
because python is not part of the "base system".  But it might be useful
to somebody else, so I link to it here too.

[1]: https://github.com/msys2/MSYS2-packages/issues/4622#issuecomment-2140990166
[2]: https://gist.github.com/jeremyd2019/8e088a72dfef44ee29ed3442957c1e65
[3]: https://gist.github.com/jeremyd2019/ac2f00ec448e75c4bd3630926201db19
[4]: https://gist.github.com/jeremyd2019/95c2cfd7eef2ed29a339860896deddec

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to