Subject: Re: tar and open files
From: Brian Dessent <[email-masked]>
To: [email-masked]
Date: Fri, 20 Feb 2004 15:45:14 -0800

"DePriest, Jason R." wrote:
> 
> For a DLL, does just unregistering the DLL do what you need?  I mean,
> running 'regsvr32 /u <dll>', put new file in place, run 'regsvr32
> <dll>'?

No.  The replacement only occurs at boot-time.

I don't know if this is quite off-topic or not but I wrote the following
perl script which reads the list of Pending File Rename Operations (to
occur at next boot time) and outputs a shell script to perform them. 
Example of its use would be:

- Run setup.exe
- try to upgrade some in-use thing
- setup.exe tells you that you need to reboot because you forget to stop
all cygwin processes
- you stop all cygwin processes
- run this script, which outputs a script to perform the pending renames
without having to reboot, assuming those files are now not open
- delete the PendingFileRenameOperations registry key with regedit or
/proc/registry
- restart processes without a reboot

It requires libwin32, but you could probably modify it to use
/proc/registry as well.  Note also that it wouldn't work without
modification for replacing cygwin1.dll since it spits out a set of 'mv'
commands, and mv requires cygwin1.dll.  It's also overly complicated
since it cygwin-izes the paths.  It would have been easier to spit out
dos commands probably.  Hindsight...

Note that this does not do any magic!  It's only for the case where you
try to install or upgrade something where you forgot to stop it first. 
It won't let you magically replace inuse files, it's only for the case
where you can stop the process, but don't feel like rebooting just to
rename some files.

There's no error checking, use at your own risk, blah blah blah.

#!/usr/bin/perl -w

use Win32::TieRegistry;

my $pr =
$Registry->{'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\PendingFileRenameOperations'};

my @list = split('\0', $pr);

print "# ", join("\n# ", @list), "\n";

while (@list) {
  my $a = shift @list;
  my $b = shift @list;
  
  if ($b) {
    print "mv -f " . fix($a) . " " . fix($b) . "\n";
  } else {
    print "rm " . fix($a) . "\n";
  }
}
        
sub fix
{
  my $in = shift;
  
  $in =~ s%^\!?\\\?\?\\%%;
  my $foo = quotemeta($in);
  chomp (my $bar = `cygpath -u $foo`);
  return "\'$bar\'";
}

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