Quantcast
Channel: PortableApps.com - Beta Testing
Viewing all articles
Browse latest Browse all 367

RMDirIfNotJunction - Removing empty directories but checking if they are junctions first

$
0
0

I'm testing an NSIS function that will remove an empty directory after checking if it is a junction. Essentially, it's an RMDir (without the /r) but checking to see if the directory referenced is a REPARSE_POINT first.

Why do this? Some users use junction points within APPDATA to redirect specific directories to other drives for their local apps. For apps like Firefox and Thunderbird, the best way to do this is to use the built-in profile manager to point to a profile on your secondary drive. Some users prefer to use junctions, though. Personally, I avoid junctions and recommend against them full stop. Junctions on Windows are incredibly buggy and probably shouldn't be used.

What happens? As NSIS uses standard Windows calls, it checks to see if a given directory is empty before removing directory for commands like RMDir. Unfortunately, due to junctions being junctions, they report as empty even though the directory they point to has things in it because the directory referenced doesn't have anything in it because it doesn't exist. aka... buggy.

Working around it. I've put together a quick function that is a drop in replacement for RMDir that will remove the directory buy only after it is checked to see if it is a junction. The eventual goal is to consider replacing RMDir calls within launchers to check for the niche users that intersperse junctions within APPDATA.

Here's the code:

; RMDirIfNotJunction 1.0 (2016-04-18)
;
; Removes an empty directory if it is not a junction
;
; Usage: ${RMDirIfNotJunction} REMOVE_PATH

Function RMDirIfNotJunction
	;Start with a clean slate
	ClearErrors
	
	;Get our parameters
	Exch $0 ;REMOVE_PATH
	Push $1 ;TempVar
	
	;Determine if it is a junction
	${GetFileAttributes} "$0""REPARSE_POINT" $1
	
	${If} $1 == 0
		;Not a junction, remove the directory if empty
		RMDir $0
	${EndIf}
	
	;Clear the stack
	Pop $1
	Pop $0
FunctionEnd

!macro RMDirIfNotJunction REMOVE_PATH
  Push `${REMOVE_PATH}`
  Call RMDirIfNotJunction
!macroend

!define RMDirIfNotJunction '!insertmacro "RMDirIfNotJunction"'

And here are a couple test launchers for FirefoxPortable.exe and ThunderbirdPortable.exe. Drop them in place of the standard launcher.

Be sure to backup your Firefox/Thunderbird Portable profile *AND* your local Firefox/Thunderbird data before testing just to be safe.

Please report back your results.

Forums:


Viewing all articles
Browse latest Browse all 367

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>