Artifact
1797c2abdb961d467816bd78c556c82545a06ce7:
Attachment "tclFCmd.diff" to
ticket [591647ffff]
added by
vincentdarley
2002-08-06 23:51:19.
0000: 49 6e 64 65 78 3a 20 74 63 6c 46 43 6d 64 2e 63 Index: tclFCmd.c
0010: 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d .===============
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 3a 20 2f ====.RCS file: /
0060: 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 63 6c 2f cvsroot/tcl/tcl/
0070: 67 65 6e 65 72 69 63 2f 74 63 6c 46 43 6d 64 2e generic/tclFCmd.
0080: 63 2c 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72 c,v.retrieving r
0090: 65 76 69 73 69 6f 6e 20 31 2e 31 38 0a 64 69 66 evision 1.18.dif
00a0: 66 20 2d 62 20 2d 75 20 2d 72 31 2e 31 38 20 74 f -b -u -r1.18 t
00b0: 63 6c 46 43 6d 64 2e 63 0a 2d 2d 2d 20 74 63 6c clFCmd.c.--- tcl
00c0: 46 43 6d 64 2e 63 09 31 38 20 4a 75 6c 20 32 30 FCmd.c.18 Jul 20
00d0: 30 32 20 31 36 3a 31 37 3a 34 38 20 2d 30 30 30 02 16:17:48 -000
00e0: 30 09 31 2e 31 38 0a 2b 2b 2b 20 74 63 6c 46 43 0.1.18.+++ tclFC
00f0: 6d 64 2e 63 09 36 20 41 75 67 20 32 30 30 32 20 md.c.6 Aug 2002
0100: 31 36 3a 35 30 3a 32 31 20 2d 30 30 30 30 0a 40 16:50:21 -0000.@
0110: 40 20 2d 34 34 38 2c 36 20 2b 34 34 38 2c 38 20 @ -448,6 +448,8
0120: 40 40 0a 20 7b 0a 20 20 20 20 20 69 6e 74 20 72 @@. {. int r
0130: 65 73 75 6c 74 3b 0a 20 20 20 20 20 54 63 6c 5f esult;. Tcl_
0140: 4f 62 6a 20 2a 65 72 72 66 69 6c 65 2c 20 2a 65 Obj *errfile, *e
0150: 72 72 6f 72 42 75 66 66 65 72 3b 0a 2b 20 20 20 rrorBuffer;.+
0160: 20 2f 2a 20 49 66 20 73 6f 75 72 63 65 20 69 73 /* If source is
0170: 20 61 20 6c 69 6e 6b 2c 20 74 68 65 6e 20 74 68 a link, then th
0180: 69 73 20 69 73 20 74 68 65 20 72 65 61 6c 20 66 is is the real f
0190: 69 6c 65 2f 64 69 72 65 63 74 6f 72 79 20 2a 2f ile/directory */
01a0: 0a 2b 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 61 .+ Tcl_Obj *a
01b0: 63 74 75 61 6c 53 6f 75 72 63 65 20 3d 20 4e 55 ctualSource = NU
01c0: 4c 4c 3b 0a 20 20 20 20 20 54 63 6c 5f 53 74 61 LL;. Tcl_Sta
01d0: 74 42 75 66 20 73 6f 75 72 63 65 53 74 61 74 42 tBuf sourceStatB
01e0: 75 66 2c 20 74 61 72 67 65 74 53 74 61 74 42 75 uf, targetStatBu
01f0: 66 3b 0a 20 0a 20 20 20 20 20 69 66 20 28 54 63 f;. . if (Tc
0200: 6c 5f 46 53 43 6f 6e 76 65 72 74 54 6f 50 61 74 l_FSConvertToPat
0210: 68 54 79 70 65 28 69 6e 74 65 72 70 2c 20 73 6f hType(interp, so
0220: 75 72 63 65 29 20 21 3d 20 54 43 4c 5f 4f 4b 29 urce) != TCL_OK)
0230: 20 7b 0a 40 40 20 2d 35 34 39 2c 38 20 2b 35 35 {.@@ -549,8 +55
0240: 31 2c 35 38 20 40 40 0a 20 09 20 2a 2f 0a 20 20 1,58 @@. . */.
0250: 20 20 20 7d 0a 20 0a 2b 23 69 66 64 65 66 20 53 }. .+#ifdef S
0260: 5f 49 53 4c 4e 4b 0a 2b 20 20 20 20 2f 2a 20 0a _ISLNK.+ /* .
0270: 2b 20 20 20 20 20 2a 20 54 6f 20 61 64 64 20 61 + * To add a
0280: 20 66 6c 61 67 20 74 6f 20 6d 61 6b 65 20 27 63 flag to make 'c
0290: 6f 70 79 27 20 63 6f 70 79 20 6c 69 6e 6b 73 20 opy' copy links
02a0: 69 6e 73 74 65 61 64 20 6f 66 20 66 69 6c 65 73 instead of files
02b0: 2c 20 77 65 20 63 6f 75 6c 64 0a 2b 20 20 20 20 , we could.+
02c0: 20 2a 20 61 64 64 20 61 20 63 6f 6e 64 69 74 69 * add a conditi
02d0: 6f 6e 20 74 6f 20 69 67 6e 6f 72 65 20 74 68 69 on to ignore thi
02e0: 73 20 27 69 66 27 20 68 65 72 65 2e 0a 2b 20 20 s 'if' here..+
02f0: 20 20 20 2a 2f 0a 2b 20 20 20 20 69 66 20 28 63 */.+ if (c
0300: 6f 70 79 46 6c 61 67 20 26 26 20 53 5f 49 53 4c opyFlag && S_ISL
0310: 4e 4b 28 73 6f 75 72 63 65 53 74 61 74 42 75 66 NK(sourceStatBuf
0320: 2e 73 74 5f 6d 6f 64 65 29 29 20 7b 0a 2b 09 2f .st_mode)) {.+./
0330: 2a 20 0a 2b 09 20 2a 20 57 65 20 77 61 6e 74 20 * .+. * We want
0340: 74 6f 20 63 6f 70 79 20 66 69 6c 65 73 20 6e 6f to copy files no
0350: 74 20 6c 69 6e 6b 73 2e 20 20 54 68 65 72 65 66 t links. Theref
0360: 6f 72 65 20 77 65 20 6d 75 73 74 20 66 6f 6c 6c ore we must foll
0370: 6f 77 20 74 68 65 0a 2b 09 20 2a 20 6c 69 6e 6b ow the.+. * link
0380: 2e 20 20 54 68 65 72 65 20 61 72 65 20 74 77 6f . There are two
0390: 20 70 75 72 70 6f 73 65 73 20 74 6f 20 74 68 69 purposes to thi
03a0: 73 20 27 73 74 61 74 27 20 63 61 6c 6c 20 68 65 s 'stat' call he
03b0: 72 65 2e 20 20 46 69 72 73 74 0a 2b 09 20 2a 20 re. First.+. *
03c0: 77 65 20 77 61 6e 74 20 74 6f 20 6b 6e 6f 77 20 we want to know
03d0: 69 66 20 74 68 65 20 6c 69 6e 6b 65 64 2d 66 69 if the linked-fi
03e0: 6c 65 2f 64 69 72 20 61 63 74 75 61 6c 6c 79 20 le/dir actually
03f0: 65 78 69 73 74 73 2c 20 61 6e 64 0a 2b 09 20 2a exists, and.+. *
0400: 20 73 65 63 6f 6e 64 2c 20 69 6e 20 74 68 65 20 second, in the
0410: 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 20 77 68 block of code wh
0420: 69 63 68 20 66 6f 6c 6c 6f 77 73 2c 20 73 6f 6d ich follows, som
0430: 65 20 32 30 20 6c 69 6e 65 73 0a 2b 09 20 2a 20 e 20 lines.+. *
0440: 64 6f 77 6e 2c 20 77 65 20 77 61 6e 74 20 74 6f down, we want to
0450: 20 63 68 65 63 6b 20 69 66 20 74 68 65 20 74 68 check if the th
0460: 69 6e 67 20 69 73 20 61 20 66 69 6c 65 20 6f 72 ing is a file or
0470: 20 64 69 72 65 63 74 6f 72 79 2e 0a 2b 09 20 2a directory..+. *
0480: 2f 0a 2b 09 69 66 20 28 54 63 6c 5f 46 53 53 74 /.+.if (Tcl_FSSt
0490: 61 74 28 73 6f 75 72 63 65 2c 20 26 73 6f 75 72 at(source, &sour
04a0: 63 65 53 74 61 74 42 75 66 29 20 21 3d 20 30 29 ceStatBuf) != 0)
04b0: 20 7b 0a 2b 09 20 20 20 20 2f 2a 20 41 63 74 75 {.+. /* Actu
04c0: 61 6c 20 66 69 6c 65 20 64 6f 65 73 6e 27 74 20 al file doesn't
04d0: 65 78 69 73 74 20 2a 2f 0a 2b 09 20 20 20 20 54 exist */.+. T
04e0: 63 6c 5f 41 70 70 65 6e 64 52 65 73 75 6c 74 28 cl_AppendResult(
04f0: 69 6e 74 65 72 70 2c 20 0a 2b 09 09 09 20 20 20 interp, .+...
0500: 20 20 22 65 72 72 6f 72 20 63 6f 70 79 69 6e 67 "error copying
0510: 20 5c 22 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 \"", Tcl_GetStr
0520: 69 6e 67 28 73 6f 75 72 63 65 29 2c 20 0a 2b 09 ing(source), .+.
0530: 09 09 20 20 20 20 20 22 5c 22 3a 20 74 68 65 20 .. "\": the
0540: 74 61 72 67 65 74 20 6f 66 20 74 68 69 73 20 6c target of this l
0550: 69 6e 6b 20 64 6f 65 73 6e 27 74 20 65 78 69 73 ink doesn't exis
0560: 74 22 2c 0a 2b 09 09 09 20 20 20 20 20 28 63 68 t",.+... (ch
0570: 61 72 20 2a 29 20 4e 55 4c 4c 29 3b 0a 2b 09 20 ar *) NULL);.+.
0580: 20 20 20 67 6f 74 6f 20 64 6f 6e 65 3b 0a 2b 09 goto done;.+.
0590: 7d 20 65 6c 73 65 20 7b 0a 2b 09 20 20 20 20 69 } else {.+. i
05a0: 6e 74 20 63 6f 75 6e 74 65 72 20 3d 20 30 3b 0a nt counter = 0;.
05b0: 2b 09 20 20 20 20 61 63 74 75 61 6c 53 6f 75 72 +. actualSour
05c0: 63 65 20 3d 20 73 6f 75 72 63 65 3b 0a 2b 09 20 ce = source;.+.
05d0: 20 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f Tcl_IncrRefCo
05e0: 75 6e 74 28 61 63 74 75 61 6c 53 6f 75 72 63 65 unt(actualSource
05f0: 29 3b 0a 2b 09 20 20 20 20 77 68 69 6c 65 20 28 );.+. while (
0600: 31 29 20 7b 0a 2b 09 09 54 63 6c 5f 4f 62 6a 20 1) {.+..Tcl_Obj
0610: 2a 70 61 74 68 20 3d 20 54 63 6c 5f 46 53 4c 69 *path = Tcl_FSLi
0620: 6e 6b 28 61 63 74 75 61 6c 53 6f 75 72 63 65 2c nk(actualSource,
0630: 4e 55 4c 4c 2c 30 29 3b 0a 2b 09 09 69 66 20 28 NULL,0);.+..if (
0640: 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a path == NULL) {.
0650: 2b 09 09 20 20 20 20 62 72 65 61 6b 3b 0a 2b 09 +.. break;.+.
0660: 09 7d 0a 2b 09 09 54 63 6c 5f 44 65 63 72 52 65 .}.+..Tcl_DecrRe
0670: 66 43 6f 75 6e 74 28 61 63 74 75 61 6c 53 6f 75 fCount(actualSou
0680: 72 63 65 29 3b 0a 2b 09 09 61 63 74 75 61 6c 53 rce);.+..actualS
0690: 6f 75 72 63 65 20 3d 20 70 61 74 68 3b 0a 2b 09 ource = path;.+.
06a0: 09 63 6f 75 6e 74 65 72 2b 2b 3b 0a 2b 09 09 2f .counter++;.+../
06b0: 2a 20 41 72 62 69 74 72 61 72 79 20 6c 69 6d 69 * Arbitrary limi
06c0: 74 20 6f 66 20 32 30 20 6c 69 6e 6b 73 20 74 6f t of 20 links to
06d0: 20 66 6f 6c 6c 6f 77 20 2a 2f 0a 2b 09 09 69 66 follow */.+..if
06e0: 20 28 63 6f 75 6e 74 65 72 20 3e 20 32 30 29 20 (counter > 20)
06f0: 7b 0a 2b 09 09 20 20 20 20 2f 2a 20 54 6f 6f 20 {.+.. /* Too
0700: 6d 61 6e 79 20 6c 69 6e 6b 73 20 2a 2f 0a 2b 09 many links */.+.
0710: 09 20 20 20 20 54 63 6c 5f 53 65 74 45 72 72 6e . Tcl_SetErrn
0720: 6f 28 45 4d 4c 49 4e 4b 29 3b 0a 2b 09 09 20 20 o(EMLINK);.+..
0730: 20 20 65 72 72 66 69 6c 65 20 3d 20 73 6f 75 72 errfile = sour
0740: 63 65 3b 0a 2b 09 09 20 20 20 20 67 6f 74 6f 20 ce;.+.. goto
0750: 64 6f 6e 65 3b 0a 2b 09 09 7d 0a 2b 09 20 20 20 done;.+..}.+.
0760: 20 7d 0a 2b 09 20 20 20 20 2f 2a 20 4e 6f 77 20 }.+. /* Now
0770: 27 61 63 74 75 61 6c 53 6f 75 72 63 65 27 20 69 'actualSource' i
0780: 73 20 74 68 65 20 63 6f 72 72 65 63 74 20 66 69 s the correct fi
0790: 6c 65 20 2a 2f 0a 2b 09 7d 0a 2b 20 20 20 20 7d le */.+.}.+ }
07a0: 20 65 6c 73 65 20 7b 0a 2b 09 61 63 74 75 61 6c else {.+.actual
07b0: 53 6f 75 72 63 65 20 3d 20 73 6f 75 72 63 65 3b Source = source;
07c0: 0a 2b 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f .+.Tcl_IncrRefCo
07d0: 75 6e 74 28 61 63 74 75 61 6c 53 6f 75 72 63 65 unt(actualSource
07e0: 29 3b 0a 2b 20 20 20 20 7d 0a 2b 23 65 6c 73 65 );.+ }.+#else
07f0: 0a 2b 20 20 20 20 61 63 74 75 61 6c 53 6f 75 72 .+ actualSour
0800: 63 65 20 3d 20 73 6f 75 72 63 65 3b 0a 2b 20 20 ce = source;.+
0810: 20 20 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 Tcl_IncrRefCou
0820: 6e 74 28 61 63 74 75 61 6c 53 6f 75 72 63 65 29 nt(actualSource)
0830: 3b 0a 2b 23 65 6e 64 69 66 0a 20 20 20 20 20 69 ;.+#endif. i
0840: 66 20 28 53 5f 49 53 44 49 52 28 73 6f 75 72 63 f (S_ISDIR(sourc
0850: 65 53 74 61 74 42 75 66 2e 73 74 5f 6d 6f 64 65 eStatBuf.st_mode
0860: 29 29 20 7b 0a 2d 09 72 65 73 75 6c 74 20 3d 20 )) {.-.result =
0870: 54 63 6c 5f 46 53 43 6f 70 79 44 69 72 65 63 74 Tcl_FSCopyDirect
0880: 6f 72 79 28 73 6f 75 72 63 65 2c 20 74 61 72 67 ory(source, targ
0890: 65 74 2c 20 26 65 72 72 6f 72 42 75 66 66 65 72 et, &errorBuffer
08a0: 29 3b 0a 2b 09 72 65 73 75 6c 74 20 3d 20 54 63 );.+.result = Tc
08b0: 6c 5f 46 53 43 6f 70 79 44 69 72 65 63 74 6f 72 l_FSCopyDirector
08c0: 79 28 61 63 74 75 61 6c 53 6f 75 72 63 65 2c 20 y(actualSource,
08d0: 74 61 72 67 65 74 2c 20 26 65 72 72 6f 72 42 75 target, &errorBu
08e0: 66 66 65 72 29 3b 0a 20 09 69 66 20 28 72 65 73 ffer);. .if (res
08f0: 75 6c 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b ult != TCL_OK) {
0900: 0a 20 09 20 20 20 20 69 66 20 28 65 72 72 6e 6f . . if (errno
0910: 20 3d 3d 20 45 58 44 45 56 29 20 7b 0a 20 09 09 == EXDEV) {. ..
0920: 2f 2a 20 0a 40 40 20 2d 35 39 38 2c 37 20 2b 36 /* .@@ -598,7 +6
0930: 35 30 2c 37 20 40 40 0a 20 09 20 20 20 20 7d 0a 50,7 @@. . }.
0940: 20 09 7d 0a 20 20 20 20 20 7d 20 65 6c 73 65 20 .}. } else
0950: 7b 0a 2d 09 72 65 73 75 6c 74 20 3d 20 54 63 6c {.-.result = Tcl
0960: 5f 46 53 43 6f 70 79 46 69 6c 65 28 73 6f 75 72 _FSCopyFile(sour
0970: 63 65 2c 20 74 61 72 67 65 74 29 3b 0a 2b 09 72 ce, target);.+.r
0980: 65 73 75 6c 74 20 3d 20 54 63 6c 5f 46 53 43 6f esult = Tcl_FSCo
0990: 70 79 46 69 6c 65 28 61 63 74 75 61 6c 53 6f 75 pyFile(actualSou
09a0: 72 63 65 2c 20 74 61 72 67 65 74 29 3b 0a 20 09 rce, target);. .
09b0: 69 66 20 28 28 72 65 73 75 6c 74 20 21 3d 20 54 if ((result != T
09c0: 43 4c 5f 4f 4b 29 20 26 26 20 28 65 72 72 6e 6f CL_OK) && (errno
09d0: 20 3d 3d 20 45 58 44 45 56 29 29 20 7b 0a 20 09 == EXDEV)) {. .
09e0: 20 20 20 20 72 65 73 75 6c 74 20 3d 20 54 63 6c result = Tcl
09f0: 43 72 6f 73 73 46 69 6c 65 73 79 73 74 65 6d 43 CrossFilesystemC
0a00: 6f 70 79 28 69 6e 74 65 72 70 2c 20 73 6f 75 72 opy(interp, sour
0a10: 63 65 2c 20 74 61 72 67 65 74 29 3b 0a 20 09 7d ce, target);. .}
0a20: 0a 40 40 20 2d 36 35 31 2c 36 20 2b 37 30 33 2c .@@ -651,6 +703,
0a30: 39 20 40 40 0a 20 20 20 20 20 7d 0a 20 20 20 20 9 @@. }.
0a40: 20 69 66 20 28 65 72 72 6f 72 42 75 66 66 65 72 if (errorBuffer
0a50: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 20 20 20 20 != NULL) {.
0a60: 20 20 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66 Tcl_DecrRef
0a70: 43 6f 75 6e 74 28 65 72 72 6f 72 42 75 66 66 65 Count(errorBuffe
0a80: 72 29 3b 0a 2b 20 20 20 20 7d 0a 2b 20 20 20 20 r);.+ }.+
0a90: 69 66 20 28 61 63 74 75 61 6c 53 6f 75 72 63 65 if (actualSource
0aa0: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 != NULL) {.+
0ab0: 20 20 20 20 20 54 63 6c 5f 44 65 63 72 52 65 66 Tcl_DecrRef
0ac0: 43 6f 75 6e 74 28 61 63 74 75 61 6c 53 6f 75 72 Count(actualSour
0ad0: 63 65 29 3b 0a 20 20 20 20 20 7d 0a 20 20 20 20 ce);. }.
0ae0: 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 3b 0a return result;.
0af0: 20 7d 0a }.