Old 30th September 2015, 09:40   #1
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
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:ialog /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
Mircea M is offline   Reply With Quote
Old 30th September 2015, 21:23   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
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?)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd October 2015, 07:39   #3
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
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...
Mircea M is offline   Reply With Quote
Old 2nd October 2015, 18:48   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
You might want to report it as a bug in the plugin...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 5th October 2015, 06:58   #5
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
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
Mircea M is offline   Reply With Quote
Old 5th October 2015, 11:04   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
Originally Posted by Mircea M View Post
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 )

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 9th October 2015, 12:59   #7
kalverson
Senior Member
 
Join Date: May 2007
Location: Maple Grove, Minnesota
Posts: 134
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;
}
kalverson is offline   Reply With Quote
Old 9th October 2015, 13:18   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
Originally Posted by kalverson View Post
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump