DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 522MYfoC2561636 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 522MYfoC2561636 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=iGtmbrmF X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A88223858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1740954879; bh=CHbJVEjne3qxYLmYNYk7ijhCtpmsD3eE0Qq7rVvJlOs=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iGtmbrmFOa4hGP3TWhdFhFEuoy6XROXpyTGkejyH0w3zNnKBPPJhaXTxgyP5kRqBp 4tyBwQLHXmU+ew4kdpPXzkt3ryauybS1R7KQCL1NqOA7f7L58/CyeE7mnvXEVt8qkd HyOU2ZjtBxDiTpu1SppRGlW0evnc8l/V9sn9AEkA= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1F1D3858D21 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E1F1D3858D21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740954767; cv=none; b=eJKgzDm45tcnxRulYzcg+hYhgsCJvhCPkvAQP8msjAEIOWWixLeLMptl6zPFHmb3dk+G881E+mRXmz1N9m4vFs25VBFYAg0kH7avebWg7kE+G2ksGUo+Nl/l62yJmoDlY+zNK1bt7MGELTD5X5XmFPCNDZ0wsjJi/xOmgMrmnGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740954767; c=relaxed/simple; bh=R6bN9YrKghtp0iPb2diA4qMoPAP+eWdo/z1adgUgSOM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=EnyKbx2TMeeaqY5ZLco9l4Pr9bGvFN4f17o9iMcVL9XNAP2GIr/w4OiluT539DC6CEe8zwGV5a+LS6xmJ9U2acMyYykob24wYDzV5Wt5sy5xu8hfvM0fkMhwIxXXOurM/kYqnkWMYJa2xUTAuHH/M+O/iDBknHo3um8XjOMHmMw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1F1D3858D21 Date: Sun, 2 Mar 2025 14:32:45 -0800 (PST) X-X-Sender: jeremyd AT resin DOT csoft DOT net To: cygwin AT cygwin DOT com Subject: Re: cleanup of in-use files moved to recycle bin In-Reply-To: Message-ID: <2a781007-8b06-db4d-7bcc-59f45fbae8b8@jdrake.com> References: MIME-Version: 1.0 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jeremy Drake via Cygwin Reply-To: Jeremy Drake Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Mon, 3 Jun 2024, Jeremy Drake via Cygwin wrote: > 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. Now that the mount points are escaped and contain the Windows volume roots starting with 3.6, here's my script. It uses bash/find/gawk. I'd welcome any ideas on improving it, I've only just started messing with gawk. (I'd started out doing grep/cut then xargs printf "%b\0" to unescape, but with gawk I can do that all in one program). It's in https://gist.github.com/jeremyd2019/4984ff0fa1f6fd8c99d7b8b244c52088 #!/bin/bash -ex IFS=. read -r cygmajor cygminor _ < <(uname -r) declare -a roots if [ "${cygmajor}" -gt 3 -o "${cygmajor}" -eq 3 -a "${cygminor}" -ge 6 ]; then # as of cygwin 3.6, volume roots are parsable from /proc/mounts # (noumount is the option that indicates a cygdrive mount) readarray -t -d $'\0' roots < <( LC_CTYPE=C LC_COLLATE=C gawk -v 'ORS=\0' -l ordchr ' $4 ~ /\/ { split($2,a,/\\0?[0-7]{1,3}/,seps) ret=a[1] for (x=2; x<=length(a); x++) ret = ret chr(strtonum("0" substr(seps[x-1],2))) a[x] print ret }' /proc/mounts) else # before that, just punt and look at the root of the drive / is mounted on root="$(cygpath -w /)" roots=("$(cygpath -u "${root:0:2}")") unset root fi declare -a trash readarray -t -d $'\0' trash < <( LC_CTYPE=C LC_COLLATE=C \ find "${roots[@]}" -maxdepth 1 -iname '$Recycle.Bin' -print0 | LC_CTYPE=C LC_COLLATE=C \ find -files0-from - -maxdepth 2 \( -name $'.\uDC6D\uDC73\uDC79\uDC73*' -o \ -name $'.\uF76D\uF773\uF779\uF773*' -o \ -name '.msys*' -o \ -name $'.\uDC63\uDC79\uDC67*' -o \ -name $'.\uF763\uF779\uF767*' -o \ -name '.cyg*' \) -print0) if (( ${#trash[@]} )); then ls -la "${trash[@]}" read -r -p "Remove? (y/N) " if [[ "${REPLY^^}" == "Y" ]]; then rm -f "${trash[@]}" fi fi -- 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