Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Rename command fails although there's no lock (http://forums.winamp.com/showthread.php?t=382532)

Mircea M 30th September 2015 09:40

Rename command fails although there's no lock
 
Hi,

I noticed a while ago that in case I am trying to rename a folder that is currently open in Windows Explorer, the operation sometimes fails. In order to try and figure out what is happening, I created a small script that uses the LockesList plugin (to see if anything is really locked):
code:
Name `LockedList Test`
OutFile LockedListTest.exe
RequestExecutionLevel admin

!define origFolder "C:\Program Files (x86)\Original"
!define newFolder "C:\Program Files (x86)\Original_Renamed"

Page Custom LockedListShow
Page instfiles

Function LockedListShow
LockedList::AddFolder "${origFolder}"
LockedList::Dialog /autonext /searching "Searching for locked files in ${origFolder}"
Pop $R0
MessageBox MB_OK "$R0"
FunctionEnd

Function renameFolder
ClearErrors
MessageBox MB_OK "Renaming ${origFolder} to ${newFolder}"
Rename "${origFolder}" "${newFolder}"
IfErrors 0 done
MessageBox MB_OK "Failed to rename"
done:
ClearErrors
FunctionEnd

Section
Call renameFolder
SectionEnd



I also have the following folder structure:
\Original
\config
\test.txt
I then execute LockedList.exe in different scenarios.
  1. All Windows Explorer windows closed
  2. Windows Explorer open with folder "Original" displayed
  3. Notepad open with Test.txt
  4. Windows Explorer open with folder Original\config displayed

Here are the results:
Case 1: LockedList returns "next" as no locks found, folder is renamed
Case 2: LockedList returns "next" as no locks found, folder is renamed
Case 3: LockedList displays Notepad.exe as a lock. I close it and it then returns "next". Rename failes (as folder Original\config displayed in Windows Explorer - since I opened the txt file)
Case 4: LockedList returns "next" as no locks found, rename failes.

Now I found this a bit "weird". Rename works ok if only the folder to be renamed is displayed in Windows Explorer but fails as soon as any subfolders thereof are displayed. Also, LockedList finds no locks and manual renaming also works.

Any idea why this might happen?

Thanks,
Mircea

Anders 30th September 2015 21:23

I think Explorer might be using oplocks (opportunistic lock) (if they are supported on directories) and I'm not sure if LockedList supports those.

Have you tried calling AddFolder for all subfolders? (I don't think this should be necessary but maybe the plugin has a bug?)

Mircea M 2nd October 2015 07:39

Hi,

yes, I tried that too but it doesn't change anything.
So, do you know of any way to Rename / Move such folders? My idea was to "kill" all Windows Explorer processes before performing the move, just to be sure, but this is not an elegant solution...

Anders 2nd October 2015 18:48

You might want to report it as a bug in the plugin...

Mircea M 5th October 2015 06:58

Hi Anders,

ok, will do that but the problem isn't actually with the plugin, I believe. As far as I can tell, the plugin does find the locks when the files are actually "really" locked. Since at the time when my test installer says it can not rename the folder, by using any other methods, it is actually possible to perform the operation, I would think there's an issue with NSIS maybe.

Mircea

Anders 5th October 2015 11:04

Quote:

Originally Posted by Mircea M (Post 3034006)
Since at the time when my test installer says it can not rename the folder, by using any other methods, it is actually possible to perform the operation, I would think there's an issue with NSIS maybe.

NSIS just calls MoveFile ( https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx )

kalverson 9th October 2015 12:59

Years ago I added a native program to do this for me which has proven reliable ever since

// chkfolder.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"

#define MAXPATH 1024

int result=0; // 0 = good - folder renames worked, not zero = bad - folder rename failed
wchar_t buf[MAXPATH]; // maxpath

int _tmain(int argc, _TCHAR* argv[])
{

// argv[1] = product folder

if (wcsnlen(argv[1], MAXPATH) > 0) {

HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);

result = _wrename(argv[1], argv[2]);

} else {
wprintf(L"product folder name must be at least one character in length.");
}

return result;
}

Anders 9th October 2015 13:18

Quote:

Originally Posted by kalverson (Post 3034299)
Years ago I added a native program to do this for me which has proven reliable ever since

_rename just calls MoveFile like NSIS.

Also, why would you use a console program if you just try to hide the console window anyway, it is going to flash up on the screen for a second.


All times are GMT. The time now is 17:21.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.