Skip to content

Commit 5a6d289

Browse files
committed
Implemented -no-acl to control ownership and ACL info
Fixed possible 'Cannot execute a program' when trying to use pkg via GetNutool in old VS2010 (MSBuild 4.0), F-47 Fixed exit with invalid key and 'pk-or-sys' for -debug All tests are now valid, including in XP
1 parent 58e25f6 commit 5a6d289

File tree

7 files changed

+145
-32
lines changed

7 files changed

+145
-32
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
# Our batch files requires CRLF for correct work.
32
# https://github.com/3F/hMSBuild/issues/2
43

54
*.bat text eol=crlf
65
*.cmd text eol=crlf
7-
*.tpl text eol=crlf
6+
7+
# (optional) hMSBuild 2.5+
8+
hMSBuild.bat text eol=lf

Readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ An attempt to provide *.NET Framework 4.x* Developer Packs (SDKs) support for mo
77
* Pure LF protected batch-script (.bat/.cmd) that does NOT require *powershell* or *dotnet-cli*;
88
* Portable and flexible solution;
99
* Internet connection is NOT needed for system mode;
10-
* Lightweight and text-based, about ~10 KB + ~18 KB;
10+
* Lightweight and text-based, about ~11 KB + ~18 KB;
1111
* Free and Open source https://github.com/3F/netfx4sdk
1212

1313
Based on [hMSBuild.bat](https://github.com/3F/hMSBuild) + [GetNuTool](https://github.com/3F/GetNuTool)
@@ -123,6 +123,8 @@ Note: only *hMSBuild.bat* 2.5+ have the same protection. Full editions ([*hMSBui
123123
-global - To use the global toolset, like hMSBuild.
124124
-no-mklink - Use direct copying instead of mklink (junction / symbolic).
125125
-stub - Use a stub instead of actual processing.
126+
-sdk-root - Custom path to the SDK root directory.
127+
-no-acl - Do not copy ownership and ACL information when direct copying.
126128
127129
-pkg-version {arg} - Specific package version in pkg mode. Where {arg}:
128130
* 1.0.3 ...
@@ -144,6 +146,7 @@ netfx4sdk -mode pkg -tfm 4.5
144146
netfx4sdk -global -mode pkg -tfm 3.5 -no-mklink -force
145147
call netfx4sdk -mode sys || call netfx4sdk -mode pkg
146148
netfx4sdk -mode sys-or-pkg
149+
netfx4sdk -mode pkg -tfm 3.5 -sdk-root "path\to" -no-mklink -no-acl
147150
```
148151

149152
## Integration with scripts

netfx4sdk.cmd

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ echo -global - To use the global toolset, like hMSBuild.
5353
echo -no-mklink - Use direct copying instead of mklink (junction / symbolic).
5454
echo -stub - Use a stub instead of actual processing.
5555
echo -sdk-root - Custom path to the SDK root directory.
56+
echo -no-acl - Do not copy ownership and ACL information when direct copying.
5657
echo.
5758
echo -pkg-version {arg} - Specific package version in pkg mode. Where {arg}:
5859
echo * 1.0.3 ...
@@ -88,6 +89,7 @@ echo %~n0 -mode pkg -tfm 4.5
8889
echo %~n0 -global -mode pkg -tfm 3.5 -no-mklink -force
8990
echo call %~n0 -mode sys ^|^| call %~n0 -mode pkg
9091
echo %~n0 -mode sys-or-pkg
92+
echo %~n0 -mode pkg -tfm 3.5 -sdk-root "path\to" -no-mklink -no-acl
9193

9294
goto endpoint
9395

@@ -108,6 +110,7 @@ set "tfm="
108110
set "kStub="
109111
set "kFallback="
110112
set "kSdkRoot="
113+
set "kNoAcl="
111114

112115
set /a ERROR_SUCCESS=0
113116
set /a ERROR_FAILED=1
@@ -118,6 +121,7 @@ set /a ERROR_ENV_W=1001
118121
set /a ERROR_HMSBUILD_UNSUPPORTED=1002
119122
set /a ERROR_HMSBUILD_NOT_FOUND=1003
120123
set /a ERROR_UNAUTHORIZED_ACCESS=1004
124+
set /a ERROR_XCP_W=1005
121125

122126
set /a ERROR_ROLLBACK=1100
123127
set /a ERROR_INVALID_KEY_OR_VALUE=1200
@@ -203,6 +207,11 @@ set key=!arg[%idx%]!
203207
set kNoMklink=1
204208
goto continue
205209
)
210+
else if [!key!]==[-no-acl]
211+
(
212+
set kNoAcl=1
213+
goto continue
214+
)
206215
else if [!key!]==[-stub]
207216
(
208217
set kStub=1
@@ -338,7 +347,7 @@ set /a "idx+=1" & if %idx% LSS !amax! goto loopargs
338347
mklink 2>nul>nul
339348
& if !ERRORLEVEL! EQU %ERROR_CMD_BAD_COMMAND_OR_FILE%
340349
(
341-
echo NOTE: '-no-mklink' is activated because links are not supported in this environment.
350+
call :warn "'-no-mklink' is activated because links are not supported in this environment."
342351
set "kNoMklink=2"
343352
)
344353
)
@@ -365,7 +374,7 @@ set /a "idx+=1" & if %idx% LSS !amax! goto loopargs
365374
set /a EXIT_CODE=%ERROR_UNAUTHORIZED_ACCESS% & goto endpoint
366375
)
367376

368-
set lDir=!lDir:msbuild.exe=!
377+
set lDir=!lDir:MSBuild.exe=!
369378

370379
:: NOTE: older xcopy doesn't like double slashes with single slashes, e.g. dir1\dir2\\file1 results as "File not found" /F-42
371380
:: that's why we need to fix the path from hmsbuild 2.5 (and older)
@@ -393,8 +402,10 @@ set /a "idx+=1" & if %idx% LSS !amax! goto loopargs
393402
set opkg=%~nx0.!kTfm!.%vpkg%
394403
if "%vpkg%"=="latest" ( set "vpkg=" ) else ( set "vpkg=/%vpkg%" )
395404

396-
if defined kDebug set engine=!engine! -debug
397-
call !engine! -GetNuTool /p:ngpackages="!npkg!!vpkg!:!opkg!" ||
405+
set gnt=!engine!
406+
if defined kDebug set gnt=!engine! -debug
407+
408+
call !gnt! -GetNuTool "!npkg!!vpkg!:!opkg!" ||
398409
(
399410
set /a EXIT_CODE=%ERROR_GNT_FAIL% & goto endpoint
400411
)
@@ -414,18 +425,20 @@ set /a "idx+=1" & if %idx% LSS !amax! goto loopargs
414425
call :copyOrLinkFolder "!dpkg!" "!tdir!"
415426
)
416427

417-
echo Done.
418-
419-
set /a EXIT_CODE=%ERROR_SUCCESS%
428+
set /a EXIT_CODE=!ERRORLEVEL!
420429
goto endpoint
421430

422431

423432
:: - - - - - - -
424433
:: Post-actions
425434
:endpoint
426435

427-
if !EXIT_CODE! NEQ 0
428-
(
436+
if !EXIT_CODE! EQU %ERROR_SUCCESS%
437+
(
438+
echo Done.
439+
exit /B %ERROR_SUCCESS%
440+
)
441+
429442
call :warn "Failed: !EXIT_CODE!"
430443
set "hmsurl=https://github.com/3F/hMSBuild"
431444

@@ -463,20 +476,32 @@ if !EXIT_CODE! NEQ 0
463476
)
464477
else if !EXIT_CODE! EQU %ERROR_UNAUTHORIZED_ACCESS%
465478
(
466-
call :warn "Unauthorized access. Make sure you have read/write permissions to the folders listed in '-debug'. Try run %~nx0 as administrator."
479+
call :warn "Unauthorized access. Make sure you have read/write permissions to the folders listed in '-debug'. Try run %~nx0 as administrator or use '-no-acl'"
467480
)
468481
else if !EXIT_CODE! EQU %ERROR_SDK_ROOT_NOT_EXIST%
469482
(
470483
call :warn "The path specified in '-sdk-root' does not exist: !kSdkRoot!. Try as -sdk-root `!kSdkRoot!` or make sure."
471484
)
485+
else if !EXIT_CODE! EQU %ERROR_XCP_W%
486+
(
487+
call :warn "Failed XCOPY. Try '-no-acl' key to avoid `Access denied` errors; Use '-debug' / '-stub' for details."
488+
)
489+
else if !EXIT_CODE! EQU %ERROR_INVALID_KEY_OR_VALUE%
490+
(
491+
exit /B !EXIT_CODE!
492+
)
493+
else
494+
(
495+
call :warn "Something went wrong. Use '-debug' and/or '-stub' keys to inspect the problem."
496+
)
472497

473498
if defined kFallback if defined tfm
474499
(
475-
echo.& echo Switch to !kFallback! mode for second attempt due to '-mode !kMode!-or-!kFallback!'
500+
echo.& echo Switch to '!kFallback!' mode for second attempt due to '-mode !kMode!-or-!kFallback!'
476501
set "kMode=!kFallback!" & set "kFallback="
477502
goto activateMode
478503
)
479-
)
504+
480505
exit /B !EXIT_CODE!
481506

482507

@@ -497,17 +522,20 @@ exit /B
497522
if defined subdirs ( set "subdirs=/E" ) else ( set "subdirs=" )
498523

499524
if not defined kStub ( call :dbgprint "xcp !subdirs!" src dst )
500-
set _x=xcopy "%src%" "%dst%" !subdirs!/I/Q/H/K/O/X/Y ::&:
525+
if defined kNoAcl ( set "_acl=" ) else ( set "_acl=/O/X" )
501526

502-
:: NOTE: possible "Invalid switch - /B" in older xcopy
527+
set _x=xcopy "%src%" "%dst%" !subdirs!/I/Q/H/K!_acl!/Y ::&:
503528

504-
if defined kNoMklink (
505-
call :stub %_x% || exit /B %ERROR_ENV_W%
529+
if defined kNoMklink
530+
(
531+
call :stub !_x! || exit /B %ERROR_XCP_W%
506532
)
507-
else (
508-
call :stub %_x%/B 2>nul || call :stub %_x% || exit /B %ERROR_ENV_W%
533+
else
534+
(
535+
:: NOTE: possible "Invalid switch - /B" in older xcopy
536+
call :stub !_x!/B 2>nul || call :stub !_x! || exit /B %ERROR_XCP_W%
509537
)
510-
exit /B 0
538+
exit /B
511539
:: :xcp
512540

513541
:checkEngine
@@ -544,7 +572,7 @@ exit /B
544572
else (
545573
call :stub "mklink" "%~2" "%~1"
546574
)
547-
exit /B 0
575+
exit /B
548576
:: :copyOrLinkFile
549577

550578
:copyOrLinkFolder {in:src} {in:dst}
@@ -554,7 +582,7 @@ exit /B 0
554582
else (
555583
call :stub "mklink" /J "%~2" "%~1"
556584
)
557-
exit /B 0
585+
exit /B
558586
:: :copyOrLinkFolder
559587

560588
:initDefaultTfm {in:version}

netfx4sdk.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Pure LF protected batch-script (.bat/.cmd) that does NOT require powershell or dotnet-cli;
1919
* Portable and flexible solution;
2020
* Internet connection is NOT needed for system mode;
21-
* Lightweight and text-based, about ~10 KB + ~18 KB;
21+
* Lightweight and text-based, about ~11 KB + ~18 KB;
2222
* Free and Open source https://github.com/3F/netfx4sdk
2323

2424
Based on hMSBuild.bat + GetNuTool

tests/a.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ exit /B 1
7171
set "tArgs=%~2"
7272
if "%~3"=="" ( set /a exCode=0 ) else set /a exCode=%~3
7373

74+
:: netfx4sdk, F-47
75+
call :cleanStream
76+
7477
if "!tArgs!" NEQ "" set tArgs=!tArgs:`="!
7578

7679
set /a gcount+=1
@@ -200,6 +203,11 @@ exit /B 0
200203
echo. & call :cprint 47 [Failed]
201204
exit /B 0
202205

206+
:cleanStream
207+
for /L %%i in (0,1,!msgIdx!) do set "msg[%%i]="
208+
set /a msgIdx=0
209+
exit /B 0
210+
203211
:printStream
204212
if "!msgIdx!"=="" exit /B 1
205213
for /L %%i in (0,1,!msgIdx!) do echo (%%i) *%~1: !msg[%%i]!

tests/keysAndLogicTests.bat

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,21 @@ set "exec=%~3" & set "wdir=%~4"
109109

110110
::_______ ------ ______________________________________
111111

112-
call a startTest "-mode sys -tfm 4.5 -force" 1202 || goto x
112+
mkdir sdkDirTest2 2>nul>nul
113+
call a startTest "-mode sys -tfm 4.5 -force -sdk-root sdkDirTest2" 1202 || goto x
113114
call a findInStreamOrFail "[*] WARN: .NET Framework v4.5 is not supported in the selected '-mode sys'" 2,n || goto x
114115
call a completeTest
116+
rmdir sdkDirTest2 2>nul>nul
115117
::_____________________________________________________
116118

117119

118120
::_______ ------ ______________________________________
119121

120-
call a startTest "-mode sys -tfm 4.6.2 -force" 1202 || goto x
122+
mkdir sdkDirTest2 2>nul>nul
123+
call a startTest "-mode sys -sdk-root sdkDirTest2 -tfm 4.6.2 -force" 1202 || goto x
121124
call a findInStreamOrFail "[*] WARN: .NET Framework v4.6.2 is not supported in the selected '-mode sys'" 2,n || goto x
122125
call a completeTest
126+
rmdir sdkDirTest2 2>nul>nul
123127
::_____________________________________________________
124128

125129

0 commit comments

Comments
 (0)