1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
+
+
+
|
/*
* tclWinFCmd.c
*
* This file implements the Windows specific portion of file manipulation
* subcommands of the "file" command.
*
* Copyright © 1996-1998 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tclWinInt.h"
#if defined (__clang__) && (__clang_major__ > 20)
#pragma clang diagnostic ignored "-Wc++-keyword"
#endif
/*
* The following constants specify the type of callback when
* TraverseWinTree() calls the traverseProc()
*/
enum TclTraverseWinTreeTypes {
DOTREE_PRED = 1, /* pre-order directory */
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
|
WIN_HIDDEN_ATTRIBUTE,
WIN_LONGNAME_ATTRIBUTE,
WIN_READONLY_ATTRIBUTE,
WIN_SHORTNAME_ATTRIBUTE,
WIN_SYSTEM_ATTRIBUTE
};
static const int attributeArray[] = {FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_HIDDEN,
0, FILE_ATTRIBUTE_READONLY, 0, FILE_ATTRIBUTE_SYSTEM};
static const int attributeArray[] = {
FILE_ATTRIBUTE_ARCHIVE, // -archive
FILE_ATTRIBUTE_HIDDEN, // -hidden
0, // -longname
FILE_ATTRIBUTE_READONLY, // -readonly
0, // -shortname
FILE_ATTRIBUTE_SYSTEM // -system
};
const char *const tclpFileAttrStrings[] = {
"-archive", "-hidden", "-longname", "-readonly",
"-shortname", "-system", NULL
"-archive",
"-hidden",
"-longname",
"-readonly",
"-shortname",
"-system",
NULL
};
const TclFileAttrProcs tclpFileAttrProcs[] = {
{GetWinFileAttributes, SetWinFileAttributes},
{GetWinFileAttributes, SetWinFileAttributes},
{GetWinFileLongName, CannotSetAttribute},
{GetWinFileAttributes, SetWinFileAttributes},
{GetWinFileShortName, CannotSetAttribute},
{GetWinFileAttributes, SetWinFileAttributes}};
{GetWinFileAttributes, SetWinFileAttributes}, // -archive
{GetWinFileAttributes, SetWinFileAttributes}, // -hidden
{GetWinFileLongName, CannotSetAttribute}, // -longname
{GetWinFileAttributes, SetWinFileAttributes}, // -readonly
{GetWinFileShortName, CannotSetAttribute}, // -shortname
{GetWinFileAttributes, SetWinFileAttributes} // -system
};
/*
* Prototype for the TraverseWinTree callback function.
*/
typedef int (TraversalProc)(const WCHAR *srcPtr, const WCHAR *dstPtr,
int type, Tcl_DString *errorPtr);
|
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
|
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
|
+
+
+
+
+
+
-
+
+
+
+
+
+
+
|
{
Tcl_DString ds;
Tcl_DString srcString, dstString;
Tcl_Obj *normSrcPtr, *normDestPtr;
int ret;
normSrcPtr = Tcl_FSGetNormalizedPath(NULL,srcPathPtr);
if (normSrcPtr == NULL) {
return TCL_ERROR;
}
if (normSrcPtr != srcPathPtr) {
Tcl_IncrRefCount(normSrcPtr);
}
normDestPtr = Tcl_FSGetNormalizedPath(NULL,destPathPtr);
if ((normSrcPtr == NULL) || (normDestPtr == NULL)) {
if (normDestPtr == NULL) {
if (normSrcPtr != srcPathPtr) {
Tcl_DecrRefCount(normSrcPtr);
}
return TCL_ERROR;
}
if (normDestPtr != destPathPtr) {
Tcl_IncrRefCount(normDestPtr);
}
Tcl_DStringInit(&srcString);
Tcl_DStringInit(&dstString);
Tcl_UtfToWCharDString(TclGetString(normSrcPtr), TCL_INDEX_NONE, &srcString);
Tcl_UtfToWCharDString(TclGetString(normDestPtr), TCL_INDEX_NONE, &dstString);
|
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
|
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
|
+
+
+
+
+
+
|
*/
Tcl_DString native;
normPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
if (normPtr == NULL) {
return TCL_ERROR;
}
if (normPtr != pathPtr) {
Tcl_IncrRefCount(normPtr);
}
Tcl_DStringInit(&native);
Tcl_UtfToWCharDString(TclGetString(normPtr), TCL_INDEX_NONE, &native);
ret = DoRemoveDirectory(&native, recursive, &ds);
Tcl_DStringFree(&native);
} else {
ret = DoRemoveJustDirectory((const WCHAR *)Tcl_FSGetNativePath(pathPtr), 0, &ds);
}
if (ret != TCL_OK) {
if (Tcl_DStringLength(&ds) > 0) {
if (normPtr != NULL &&
!strcmp(Tcl_DStringValue(&ds), TclGetString(normPtr))) {
*errorPtr = pathPtr;
} else {
*errorPtr = Tcl_DStringToObj(&ds);
}
Tcl_IncrRefCount(*errorPtr);
}
Tcl_DStringFree(&ds);
}
if (normPtr && normPtr != pathPtr) {
Tcl_DecrRefCount(normPtr);
}
return ret;
}
static int
DoRemoveJustDirectory(
|