How do I stop cygwin from creating undeletable files? Or can I delete them somehow?

2

1

Once in a while cygwin seem to create files that doesn't seem to be removable at all. When deleting from cygwin it just doesn't happen (rm says nothing, but the file is still there). When trying from the explorer it says that I need permissions from the administrator (and I am the administrator, the delete item in the drop down menu has a shield and I guess that means that I try this with administrator priveleges). When trying from total commander I first get error and am asked if I wan't to retry as administrator and then I still doesn't seem to have permission to delete the file.

I get the same problem if I try to view the file. Problems when I try to view the security properties - must press a shield-button to become administrator and then am told that I'm not allowed to view it unless I take ownership (which I'm not allowed to do).

Using the cygwin shell I'm allowed to view, but not modify the ACL (even if the shell is being run as the administrator):

$ getfacl makefile.wine
# file: makefile.wine
# owner: Unknown+User
# group: Unknown+Group
user::rw-
group::r--
other:---
$ setfacl -b makefile.wine
setfacl: Permission denied

However when restarted windows there were no problems in just removing the files.

Why/how do cygwin create these files (I figured out that one was created when running sed -i)? How can I avoid this? And finally is there any sane way to delete the file?

skyking

Posted 2016-05-13T13:21:24.707

Reputation: 141

Try these steps - http://stackoverflow.com/questions/3739477/undeletable-file-in-cygwin#3769631

– hkdtam – 2016-05-13T14:08:57.750

@hkdtam I'm not sure which steps you mean. The answer linked to seem to suggest to just wait and the file should go away, that hasn't happened. The other solutions basically show the same result, I don't seem to be allowed to do any of those things (even if running the shell as administrator). – skyking – 2016-05-16T05:24:26.907

Answers

1

cygwin should not create undeletable files, at least not anymore. Assuming you have an updated installation (cygwin 2.5.1) : check the file ACLs with: getfacl "filename" you can sanitize the ACL permission with : setfacl -b "filename" See manuals of getfacl and setfacl for details. Additional reading https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-files

As you have from getfacl

owner: Unknown+User

group: Unknown+Group

It means cygwin does not recognize the owner. Two possibilities :

1) the owner is not anymore valid in the windows machine

2) you are using some type of VPN or Domain connection and the windows database user is not accessible in specific conditions.

As windows admin you should be able to change the owner, also from cygwin.

matzeri

Posted 2016-05-13T13:21:24.707

Reputation: 1 662

I seem to be running cygwin 2.5.0, maybe 2.5.1 wouldn't create these files. However your proposed solution for deleting the file doesn't seem to work. – skyking – 2016-05-16T05:25:41.673

setfacl -b "filename" does not delete the file. but it sanitize the ACL. After you can change permissions and delete as you want. – matzeri – 2016-05-16T09:06:59.053

Does setfacl sanitize the ACL even if it displays the "setfacl: Permission denied" message? In that case it's a confusing diagnostic... – skyking – 2016-05-16T09:09:18.567

What is the output of icacls "filename" ? – matzeri – 2016-05-16T09:13:22.740

@matzeri Same situation, get an access is denied from icacls – Prodigle – 2019-04-05T15:45:09.930

0

Please try with the takeown command. In an admin privilege CMD shell, issue the following command,

takeown /F makefile.wine

and see now if you can remove it,

rm makefile.wine

Update: Thanks for reporting and that was my oversight. After the takeown command, can you do a right-click over that file on explorer to view about the ownership information and do adjustment from there?

hkdtam

Posted 2016-05-13T13:21:24.707

Reputation: 309

As noted, that was among the solution you linked to which did not work. – skyking – 2016-05-16T06:20:07.407

0

I've finally solved this, use Process Explorer (by default in recent windows versions) search in handles for any process using that filename and kill the process.

I've detailed everything about this in my blog.

Don't try to restore the permissions, that won't work.

Miguel Ortiz

Posted 2016-05-13T13:21:24.707

Reputation: 121

1Welcome to Super User! We prefer answers to be as self-contained as possible, so could you please [edit] your answer to include the relevant information from the article in case the link breaks? For more information, see [answer]. – Ben N – 2017-06-06T15:20:44.440

0

I had the same issue with Cygwin but had no admin right. I had folders with permissions like this:

d---r-xr-x    1 jac  root        0 Feb  7 13:25 ciao

In my case I solved like this:

  1. From Windows explorer, right click on the file/folder and select properties.
  2. Go to Security tab.
  3. In: "Group or user names" click on Edit...
  4. In: "Group or user names" click on Add...
  5. In: Enter the object names to select enter your user name
  6. Press Ok, if multiple names are found you might need to confirm which one is your name
  7. Select your user and allow it full control over the file by checking the checkbox.
  8. Press OK in all dialogs, you should be now able to delete the file.

Tested on Windows 7.

Hope that can help anybody else facing the same issue.

Jacopo Gobbi

Posted 2016-05-13T13:21:24.707

Reputation: 1

This will only work if the ACL isn't corrupted. As in OP's situation, ACL cannot recognise the valid owner so any&all access to permissions will be blocked. – Prodigle – 2019-04-05T15:42:25.907