Why can't I rename a folder?
-
Given a known account on a Windows 2008 R2 server and a Powershell script running
mv components .\old
, what are the reasons I wouldn't be able to rename a folder?The error is
Access to the path 'C:\webfiles\components' is denied. + CategoryInfo : WriteError: (C:\webfiles\components:DirectoryInfo) [Move-Item], IOException + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
My account is
- An administrator on the box
- Part of a group explicitly given Full Control over the C:\Webfiles directory
- Authenticating correctly, since I was able to remotely connect to the machine
- Instructing every instance of Coldfusion on the machine to stop before it tries to rename anything in the folder it serves from
Note: I don't know much at all about administering Windows servers.
-
@Yamikuronue Check the directory in Explorer for a deny ACL?
-
Does something else have a file in the folder open? Or the folder itself?
-
@FrostCat I don't know much about ACLs but looking over this list, the word 'Deny' does not appear anywhere, and it seems to match the Security tab in Explorer as far as which groups have which permissions.
-
@loopback0 said in Why can't I rename a folder?:
Does something else have a file in the folder open? Or the folder itself?
How can I check that?
-
@Yamikuronue said in Why can't I rename a folder?:
@loopback0 said in Why can't I rename a folder?:
Does something else have a file in the folder open? Or the folder itself?
How can I check that?
Process Explorer, namely Find > Find Handle or DLL.
-
@Yamikuronue said in Why can't I rename a folder?:
How can I check that?
@Deadfast said in Why can't I rename a folder?:
Process Explorer
Yeah, that.
-
also, try just doing the move from cmd.exe and see if you get a different error.
-
@Yamikuronue said in Why can't I rename a folder?:
How can I check that?
rebooting the server would force close anything that has it open.....
not that that's a good idea
-
@Yamikuronue you can also open in administrator mode, which often resolves lock issues. It even works for file explorer to let you drag folders into visual studio =D
Often with web stuff a browser tab is open that accesses an image or file, or a notepad is open.
Your error also says fully qualified error, so try using a quoted fully qualified path. It might not understand you have a local folder old, because you're using a backslash instead of forward slash.
-
@loopback0 said in Why can't I rename a folder?:
Does something else have a file in the folder open? Or the folder itself?
Based on the name of the folder, I'd guess IIS.
-
@Matches said in Why can't I rename a folder?:
Often with web stuff a browser tab is open that accesses an image or file
I've found Chrome to be particularly clingy to files it's downloaded; if it's not that, it's Windows Defender Service taking half an hour to work out if a 1kb text file is safe or not
-
@blakeyrat said in Why can't I rename a folder?:
I'd guess IIS.
Could be IIS. Not sure if we've switched to Apache on Windows. Can't find either in the services list. I'll ask the server guy when we reconvene this afternoon.
-
@Matches said in Why can't I rename a folder?:
a browser tab is open
On a server, though? We don't have extra stuff open that I can see.
-
@Deadfast said in Why can't I rename a folder?:
Process Explorer,
I'll have to get them to do it, I don't have an easy way to get it onto the machine but they have the ability to clone it locally and lift the various restrictions so we can mess with it.
-
@Yamikuronue IIS may not be listed as
iis.exe
; I think it actually usesw3wp.exe
because raisins
-
@Yamikuronue Can they not just restart it?
-
@RaceProUK World Wide Web Publishing Service? That seems to be started. So that's IIS then? Awesome.
-
@loopback0 This is a recurring problem on machines that are rebooted nightly, so when it reboots, whatever's got the lock is clearly coming back up. If I know what it is my script can stop it before it deploys.
-
-
@loopback0 To clarify: no idea if IIS has the lock but I now know we run IIS on these machines and not Apache.
-
@Yamikuronue said in Why can't I rename a folder?:
So that's IIS then?
Yep. Well, to be ic, it's the webserver part of IIS; other worker processes handle FTP and other things.
-
@Yamikuronue It looks like a folder IIS will have open if it's running, so try stopping IIS and then messing with the folder.
iisreset /stop
-
@Yamikuronue said in Why can't I rename a folder?:
@loopback0 This is a recurring problem on machines that are rebooted nightly, so when it reboots, whatever's got the lock is clearly coming back up. If I know what it is my script can stop it before it deploys.
In that case, it's a virtual certainty that it's a Service.
If you do it right after server boot, you can stop IIS, do your folder work, then restart it. You probably don't want to do that at any other time, but at boot time you're just adding a few seconds to the downtime the site already has.
Make sure you check the response codes to the Service stop and resume requests, as those operations can fail and the OS only tries to restart Services after they crash, not after they fail a manual start.
-
@Yamikuronue said in Why can't I rename a folder?:
Instructing every instance of Coldfusion on the machine to stop before it tries to rename anything in the folder it serves from
Have those stops completed?
-
@PleegWat Yes; after the umpteen log entries that say "Waiting for service to stop" we then wait another 10 seconds just to make total sure.
IIS seems to have a lock on some images and static assets that it must be configured to serve directly.
-
@Deadfast said in Why can't I rename a folder?:
@Yamikuronue said in Why can't I rename a folder?:
@loopback0 said in Why can't I rename a folder?:
Does something else have a file in the folder open? Or the folder itself?
How can I check that?
Process Explorer, namely Find > Find Handle or DLL.
Actually I'll recommand to parse output from "handle.exe" in Sysinternal Suite to get the process names, then force close the handles.
In this way you can automate the process in your code.
Just make sure all programs that you'll use on that folder handles I/O exceptions gracefully.
-
@cheong said in Why can't I rename a folder?:
Just make sure all programs that you'll use on that folder handles I/O exceptions gracefully.
And how exactly are you supposed to make that sure before you do it? What if they don't?
-
@RaceProUK said in Why can't I rename a folder?:
@Yamikuronue IIS may not be listed as
iis.exe
; I think it actually usesw3wp.exe
because raisinsThis is because IIS is not a single process, instead there are a couple. The 'World Wide Web Publishing Service' (w3svc) service is the root process, which spawns a child worker process (w3wp) for each configured application pool.
@loopback0 said in Why can't I rename a folder?:
@Yamikuronue It looks like a folder IIS will have open if it's running, so try stopping IIS and then messing with the folder.
iisreset /stop
That stops IIS completely, which is not something I would recommend. Just stopping the application pool should be enough to free locks.
-
@AlexMedia Yes, I know. Stop the application pool(s) instead if that works. Either way, to release the files it's using you need to make it unavailable.
I'm guessing no-one is going to be making a Production site (or sites) unavailable while in use, so it shouldn't really matter.
-
Thanks guys. I've pushed a modification to stop the IIS service when we're already stopping the coldfusion service. We already assume we're taking an outage when we deploy, hence the midnight deploy window, just before our nightly reboot.
-
@anotherusername said in Why can't I rename a folder?:
@cheong said in Why can't I rename a folder?:
Just make sure all programs that you'll use on that folder handles I/O exceptions gracefully.
And how exactly are you supposed to make that sure before you do it? What if they don't?
You should have rough idea on what software "should" be using the folder.
Generally I have no little concern on software that I'm not responsible for (except, say, backup software. However these type of software usually have "continue on error" option). :P
-
@cheong I've seen bad things happen when I tried to kill Windows' handle on a file that it was sharing (after all other options short of rebooting failed). As in, nothing could connect to the share anymore.
-
Balls. A QA server fell over today.
build 06-Apr-2016 10:05:15 Stopping Coldfusion build 06-Apr-2016 10:05:18 WARNING: Waiting for service 'Macromedia JRun CFusion Server (Macromedia JRun build 06-Apr-2016 10:05:18 CFusion Server)' to finish stopping... build 06-Apr-2016 10:05:20 WARNING: Waiting for service 'Macromedia JRun CFusion Server (Macromedia JRun build 06-Apr-2016 10:05:20 CFusion Server)' to finish stopping... build 06-Apr-2016 10:05:22 WARNING: Waiting for service 'Macromedia JRun CFusion Server (Macromedia JRun build 06-Apr-2016 10:05:22 CFusion Server)' to finish stopping... build 06-Apr-2016 10:05:32 Stopping Adobe ColdFusion 9 AS [redacted process name] build 06-Apr-2016 10:05:42 Stopping Adobe ColdFusion 9 AS [redacted process name] build 06-Apr-2016 10:05:52 Stopping IIS 06-Apr-2016 10:09:26 WARNING: Waiting for service 'World Wide Web Publishing Service (W3SVC)' to 06-Apr-2016 10:09:26 finish stopping... 06-Apr-2016 10:09:28 WARNING: Waiting for service 'World Wide Web Publishing Service (W3SVC)' to 06-Apr-2016 10:09:28 finish stopping... 06-Apr-2016 10:09:30 WARNING: Waiting for service 'World Wide Web Publishing Service (W3SVC)' to 06-Apr-2016 10:09:30 finish stopping... 06-Apr-2016 10:09:32 WARNING: Waiting for service 'World Wide Web Publishing Service (W3SVC)' to 06-Apr-2016 10:09:32 finish stopping... 06-Apr-2016 10:09:34 WARNING: Waiting for service 'World Wide Web Publishing Service (W3SVC)' to 06-Apr-2016 10:09:34 finish stopping... 06-Apr-2016 10:09:44 Deploying 06-Apr-2016 10:09:45 Downloading from [build server] 06-Apr-2016 10:09:45 Access to the path 'C:\webfiles\lib' is denied.
So it's not coldfusion, the other coldfusion instances, or IIS.
-
@Yamikuronue said in Why can't I rename a folder?:
So it's not coldfusion, the other coldfusion instances, or IIS.
Has someone decided to run antivirus software on those systems?
-
@dkf Maybe.
-
Why not run a copy of "handle" on the machine and see what process is holding the handle?
IMO it's much more accurate than wild guess.
-
@cheong said in Why can't I rename a folder?:
run a copy of "handle" on the machine and see what process is holding the handle
This. Put it in the script so it logs what had the handle if the script fails again.
C:\>handle new.7z | find "pid" 7zFM.exe pid: 13064 type: File 1F0: C:\New.7z
There you go.
-
If renaming only at boot time is acceptable, Windows has an inbuilt facility to do that very thing. Easiest way to invoke it from most scripts will be via Sysinternals MoveFile. In Powershell you can call the relevant DLL function directly.
Possible gotcha: MoveFileEx only works if the source and destination are in the same filesystem; the MOVEFILE_DELAY_UNTIL_REBOOT and MOVEFILE_COPY_ALLOWED options are mutually exclusive.
-
@flabdablet said in Why can't I rename a folder?:
If renaming only at boot time is acceptable
It's not.
-
@Yamikuronue it sounds like you're trying to rename a folder that really shouldn't go away (according to the software that's trying to use it).
My question is why? You might be better off moving the contents of that folder to a new folder of the new name that you wanted. Then you're left with the empty folder by the old name (at least until the next reboot, since you can schedule it to be deleted then). Will that still be a problem? If so, why?
-
At this point someone needs to be running a tool designed to show you exactly what is using that folder (or a file in it).
-
@anotherusername said in Why can't I rename a folder?:
You might be better off moving the contents of that folder
That horse is so far out of the barn he's at the glue factory >.>
-
@Yamikuronue said in Why can't I rename a folder?:
We already assume we're taking an outage when we deploy, hence the midnight deploy window, just before our nightly reboot.
Could your deploy script not just put everything that will need to go in
C:\webfiles\components
intoC:\webfiles\new
, then set up a couple of boot-time MoveFileExes to moveC:\webfiles\components
toC:\webfiles\old
andC:\webfiles\new
toC:\webfiles\components
? That's essentially how Windows Update deals with this kind of thing.
-
@flabdablet said in Why can't I rename a folder?:
set up a couple of boot-time
Why are you obsessed with boot-time? There's no reboot involved when we deploy. Rebooting happens on a schedule entirely divorced from the promotion schedule these days.
-
@Yamikuronue Mainly because you mentioned a midnight deploy window just before your nightly reboot.
-
@flabdablet Ah. Whatever I engineer has to allow for our midday deploys as well.
-
@Yamikuronue In that case you really have no option but identifying and temporarily stopping whatever service is holding your target folder open. You could still do the components->old, new->components rename dance to minimize required service downtime.
-
The reason I don't move the contents is that the archive is created to unpack to the folder it should go in, so I'd have to adjust archive creation, and we're cross-platform, so I'd have to adjust the linux scripts as well, and that introduces extra risk.
What the powershell script is doing is renaming
components
toold
, then unpackingcomponents.tar.gz
which unpacks tocomponents
.I am not an expert in:
- Powershell
- Archive formats
- Linux shell scripts
- IIS
- Apache
- Coldfusion
So this is particularly frustrating to me :/ Sorry if I'm a bit snippy.
-
@anotherusername said in Why can't I rename a folder?:
it sounds like you're trying to rename a folder that really shouldn't go away (according to the software that's trying to use it).
Usual cause for that on Windows is that the "software that's trying to use it" has got some file open and/or locked inside the affected folder. Unlike Unix, locking a file on Windows also locks the entire chain of containing directories, all the way back to the root, against being renamed or deleted.