 |
Changeset 3887
- Timestamp:
- 08/18/08 14:44:53
(4 months ago)
- Author:
- keinfarbton
- Message:
merged from trunk -r 3830:3855
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3886 |
r3887 |
|
| 40 | 40 | version(!Windows) { |
|---|
| 41 | 41 | exclude += tango/sys/win32/CodePage.d |
|---|
| | 42 | exclude += tango/sys/win32/SpecialPath.d |
|---|
| 42 | 43 | } |
|---|
| 43 | 44 | |
|---|
| r3886 |
r3887 |
|
| 1 | 1 | [concurrency/fiber_test.d] |
|---|
| 2 | 2 | buildflags += -unittest |
|---|
| | 3 | |
|---|
| 3 | 4 | [conduits/composite.d] |
|---|
| 4 | 5 | [conduits/createzip.d] |
|---|
| … | … | |
| 22 | 23 | [conduits/shuffle.d] |
|---|
| 23 | 24 | [conduits/unifile.d] |
|---|
| | 25 | |
|---|
| 24 | 26 | [console/hello.d] |
|---|
| 25 | 27 | [console/stdout.d] |
|---|
| | 28 | |
|---|
| 26 | 29 | [logging/chainsaw.d] |
|---|
| 27 | 30 | [logging/logging.d] |
|---|
| 28 | 31 | [logging/multilog.d] |
|---|
| | 32 | |
|---|
| 29 | 33 | [manual/chapterStorage.d] |
|---|
| | 34 | |
|---|
| 30 | 35 | [networking/homepage.d] |
|---|
| 31 | 36 | [networking/httpget.d] |
|---|
| … | … | |
| 33 | 38 | [networking/sockethello.d] |
|---|
| 34 | 39 | [networking/socketserver.d] |
|---|
| | 40 | |
|---|
| 35 | 41 | #[system/arguments.d] |
|---|
| 36 | 42 | [system/localtime.d] |
|---|
| 37 | 43 | [system/normpath.d] |
|---|
| 38 | 44 | [system/process.d] |
|---|
| | 45 | |
|---|
| 39 | 46 | [text/formatalign.d] |
|---|
| 40 | 47 | [text/formatindex.d] |
|---|
| … | … | |
| 43 | 50 | [text/token.d] |
|---|
| 44 | 51 | [text/xmldom.d] |
|---|
| 45 | | buildflags += -Jtext |
|---|
| 46 | 52 | [text/xmlpull.d] |
|---|
| 47 | | buildflags += -Jtext |
|---|
| 48 | 53 | [text/xmlsax.d] |
|---|
| 49 | | buildflags += -Jtext |
|---|
| 50 | 54 | [text/xmlpath.d] |
|---|
| | 55 | |
|---|
| | 56 | [vfs/vfscan.d] |
|---|
| | 57 | [vfs/vfscanregex.d] |
|---|
| | 58 | [vfs/vfshuffle.d] |
|---|
| 51 | 59 | [vfs/vfszip.d] |
|---|
| 52 | 60 | version (Windows) { |
|---|
| r3724 |
r3887 |
|
| 74 | 74 | @jake text\xmlsax.d -I.. -op |
|---|
| 75 | 75 | |
|---|
| | 76 | @rem ########################################################################### |
|---|
| | 77 | @rem # VFS EXAMPLES |
|---|
| | 78 | @rem ########################################################################### |
|---|
| | 79 | |
|---|
| | 80 | @jake vfs\vfscan.d -I.. -op |
|---|
| | 81 | @jake vfs\vfscanregex.d -I.. -op |
|---|
| | 82 | @jake vfs\vfshuffle.d -I.. -op |
|---|
| | 83 | @jake vfs\vfszip.d -I.. -op -L"zlib;libbz2" |
|---|
| | 84 | |
|---|
| 76 | 85 | @rem FINI |
|---|
| 77 | 86 | |
|---|
| r3726 |
r3887 |
|
| 710 | 710 | else |
|---|
| 711 | 711 | // no more space in the buffer? |
|---|
| 712 | | if (writable is 0) |
|---|
| | 712 | if (writable is 0 && expand(0) is 0) |
|---|
| 713 | 713 | error ("Token is too large to fit within buffer"); |
|---|
| 714 | 714 | |
|---|
| … | … | |
| 1112 | 1112 | extent += size; |
|---|
| 1113 | 1113 | } |
|---|
| | 1114 | } |
|---|
| | 1115 | |
|---|
| | 1116 | /*********************************************************************** |
|---|
| | 1117 | |
|---|
| | 1118 | Expand existing buffer space |
|---|
| | 1119 | |
|---|
| | 1120 | Returns: |
|---|
| | 1121 | Available space, without any expansion |
|---|
| | 1122 | |
|---|
| | 1123 | Remarks: |
|---|
| | 1124 | Make some additional room in the buffer, of at least the |
|---|
| | 1125 | given size. This can be used by subclasses as appropriate |
|---|
| | 1126 | |
|---|
| | 1127 | ***********************************************************************/ |
|---|
| | 1128 | |
|---|
| | 1129 | protected uint expand (uint size) |
|---|
| | 1130 | { |
|---|
| | 1131 | return writable; |
|---|
| 1114 | 1132 | } |
|---|
| 1115 | 1133 | |
|---|
| … | … | |
| 1518 | 1536 | |
|---|
| 1519 | 1537 | if (size + index > dimension) |
|---|
| 1520 | | makeRoom (size); |
|---|
| | 1538 | expand (size); |
|---|
| 1521 | 1539 | |
|---|
| 1522 | 1540 | // populate tail of buffer with new content |
|---|
| … | … | |
| 1543 | 1561 | { |
|---|
| 1544 | 1562 | if (length > writable) |
|---|
| 1545 | | makeRoom (length); |
|---|
| | 1563 | expand (length); |
|---|
| 1546 | 1564 | |
|---|
| 1547 | 1565 | copy (src, length); |
|---|
| … | … | |
| 1561 | 1579 | { |
|---|
| 1562 | 1580 | if (writable <= increment/8) |
|---|
| 1563 | | makeRoom (increment); |
|---|
| | 1581 | expand (increment); |
|---|
| 1564 | 1582 | |
|---|
| 1565 | 1583 | return write (&src.read); |
|---|
| … | … | |
| 1585 | 1603 | /*********************************************************************** |
|---|
| 1586 | 1604 | |
|---|
| 1587 | | make some room in the buffer |
|---|
| 1588 | | |
|---|
| 1589 | | ***********************************************************************/ |
|---|
| 1590 | | |
|---|
| 1591 | | private uint makeRoom (uint size) |
|---|
| | 1605 | Expand existing buffer space |
|---|
| | 1606 | |
|---|
| | 1607 | Returns: |
|---|
| | 1608 | Available space after adjustment |
|---|
| | 1609 | |
|---|
| | 1610 | Remarks: |
|---|
| | 1611 | Make some additional room in the buffer, of at least the |
|---|
| | 1612 | given size. This can be used by subclasses as appropriate |
|---|
| | 1613 | |
|---|
| | 1614 | ***********************************************************************/ |
|---|
| | 1615 | |
|---|
| | 1616 | override uint expand (uint size) |
|---|
| 1592 | 1617 | { |
|---|
| 1593 | 1618 | if (size < increment) |
|---|
| … | … | |
| 1596 | 1621 | dimension += size; |
|---|
| 1597 | 1622 | data.length = dimension; |
|---|
| 1598 | | return writable(); |
|---|
| | 1623 | return writable; |
|---|
| 1599 | 1624 | } |
|---|
| 1600 | 1625 | } |
|---|
| r3726 |
r3887 |
|
| 22 | 22 | |
|---|
| 23 | 23 | Conduit abstract base-class, implementing interface IConduit. |
|---|
| 24 | | Only the conduit-specific read(), write(), fileHandle() and |
|---|
| 25 | | bufferSize() need to be implemented for a concrete conduit |
|---|
| | 24 | Only the conduit-specific read(), write(), and |
|---|
| | 25 | bufferSize() need to be implemented for a concrete conduit |
|---|
| 26 | 26 | implementation. See FileConduit for an example. |
|---|
| 27 | 27 | |
|---|
| … | … | |
| 39 | 39 | *******************************************************************************/ |
|---|
| 40 | 40 | |
|---|
| 41 | | class Conduit : IConduit, ISelectable |
|---|
| | 41 | class Conduit : IConduit |
|---|
| 42 | 42 | { |
|---|
| 43 | 43 | /*********************************************************************** |
|---|
| … | … | |
| 56 | 56 | |
|---|
| 57 | 57 | abstract uint bufferSize (); |
|---|
| 58 | | |
|---|
| 59 | | /*********************************************************************** |
|---|
| 60 | | |
|---|
| 61 | | Models a handle-oriented device. We need to revisit this |
|---|
| 62 | | |
|---|
| 63 | | TODO: figure out how to avoid exposing this in the general |
|---|
| 64 | | case |
|---|
| 65 | | |
|---|
| 66 | | ***********************************************************************/ |
|---|
| 67 | | |
|---|
| 68 | | abstract Handle fileHandle (); |
|---|
| 69 | 58 | |
|---|
| 70 | 59 | /*********************************************************************** |
|---|
| … | … | |
| 459 | 448 | |
|---|
| 460 | 449 | |
|---|
| | 450 | |
|---|
| r3724 |
r3887 |
|
| 27 | 27 | *******************************************************************************/ |
|---|
| 28 | 28 | |
|---|
| 29 | | class DeviceConduit : Conduit |
|---|
| | 29 | class DeviceConduit : Conduit, ISelectable |
|---|
| 30 | 30 | { |
|---|
| 31 | 31 | /// expose in superclass definition also |
|---|
| … | … | |
| 92 | 92 | ***************************************************************/ |
|---|
| 93 | 93 | |
|---|
| 94 | | final override Handle fileHandle () |
|---|
| | 94 | final Handle fileHandle () |
|---|
| 95 | 95 | { |
|---|
| 96 | 96 | return cast(Handle) handle; |
|---|
| … | … | |
| 241 | 241 | |
|---|
| 242 | 242 | |
|---|
| | 243 | |
|---|
| r3886 |
r3887 |
|
| 14 | 14 | author: Kris |
|---|
| 15 | 15 | |
|---|
| 16 | | FilePath combined a means of efficiently editing and extracting |
|---|
| 17 | | path components and of accessing the underlying file system. |
|---|
| 18 | | |
|---|
| 19 | | Use module Path.d instead when you need only pedestrian access to |
|---|
| 20 | | the file-system, and are not manipulating the path components. Use |
|---|
| 21 | | FilePath for other scenarios, since it will often be notably more |
|---|
| 22 | | efficient |
|---|
| | 16 | FilePath provides a means to efficiently edit path components and |
|---|
| | 17 | of accessing the underlying file system. |
|---|
| | 18 | |
|---|
| | 19 | Use module Path.d instead when you need pedestrian access to the |
|---|
| | 20 | file-system, and are not mutating the path components themselves |
|---|
| 23 | 21 | |
|---|
| 24 | 22 | *******************************************************************************/ |
|---|
| … | … | |
| 51 | 49 | |
|---|
| 52 | 50 | FilePath is designed to be transformed, thus each mutating method |
|---|
| 53 | | modifies the internal content. There is a read-only base-class |
|---|
| 54 | | called PathView, which can be used to provide a view into the |
|---|
| 55 | | content as desired. |
|---|
| | 51 | modifies the internal content. |
|---|
| 56 | 52 | |
|---|
| 57 | 53 | Note that patterns of adjacent '.' separators are treated specially |
|---|
| 58 | | in that they will be assigned to the name instead of the suffix. In |
|---|
| 59 | | addition, a '.' at the start of a name signifies it does not belong |
|---|
| 60 | | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| 61 | | |
|---|
| 62 | | Note also that normalization of path-separators occurs by default. |
|---|
| 63 | | This means that the use of '\' characters will be converted into |
|---|
| 64 | | '/' instead while parsing. To mutate the path into an O/S native |
|---|
| 65 | | version, use the native() method. To obtain a copy instead, use the |
|---|
| 66 | | path.dup.native sequence |
|---|
| | 54 | in that they will be assigned to the name where there is no distinct |
|---|
| | 55 | suffix. In addition, a '.' at the start of a name signifies it does |
|---|
| | 56 | not belong to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 57 | Patterns of intermediate '.' characters will otherwise be assigned |
|---|
| | 58 | to the suffix, such that "file....suffix" includes the dots within |
|---|
| | 59 | the suffix itself [see ext() for a suffix without dots]. |
|---|
| 67 | 60 | |
|---|
| 68 | 61 | *******************************************************************************/ |
|---|
| … | … | |
| 121 | 114 | this (Cutf8 filepath = null) |
|---|
| 122 | 115 | { |
|---|
| 123 | | set (filepath); |
|---|
| | 116 | set (filepath, true); |
|---|
| 124 | 117 | } |
|---|
| 125 | 118 | |
|---|
| … | … | |
| 435 | 428 | FilePath set (FilePath path) |
|---|
| 436 | 429 | { |
|---|
| 437 | | return set (path.toString); |
|---|
| 438 | | } |
|---|
| 439 | | |
|---|
| 440 | | /*********************************************************************** |
|---|
| 441 | | |
|---|
| 442 | | Reset the content of this path, and reparse. |
|---|
| 443 | | |
|---|
| 444 | | ***********************************************************************/ |
|---|
| 445 | | |
|---|
| 446 | | final FilePath set (Cutf8 path) |
|---|
| | 430 | return set (path.toString, false); |
|---|
| | 431 | } |
|---|
| | 432 | |
|---|
| | 433 | /*********************************************************************** |
|---|
| | 434 | |
|---|
| | 435 | Reset the content of this path, and reparse. There's an |
|---|
| | 436 | optional boolean flag to convert the path into standard |
|---|
| | 437 | form, before parsing (converting '\' into '/') |
|---|
| | 438 | |
|---|
| | 439 | ***********************************************************************/ |
|---|
| | 440 | |
|---|
| | 441 | final FilePath set (Cutf8 path, bool convert = false) |
|---|
| 447 | 442 | { |
|---|
| 448 | 443 | p.end_ = path.length; |
|---|
| … | … | |
| 450 | 445 | expand (p.end_); |
|---|
| 451 | 446 | if (p.end_) |
|---|
| 452 | | p.fp[0 .. p.end_] = path; |
|---|
| | 447 | { |
|---|
| | 448 | p.fp[0 .. p.end_] = path; |
|---|
| | 449 | if (convert) |
|---|
| | 450 | .standard (p.fp [0 .. p.end_]); |
|---|
| | 451 | } |
|---|
| 453 | 452 | |
|---|
| 454 | 453 | p.fp[p.end_] = '\0'; |
|---|
| … | … | |
| 621 | 620 | /*********************************************************************** |
|---|
| 622 | 621 | |
|---|
| 623 | | Parse the path spec |
|---|
| | 622 | Parse the path spec, and mutate '\' into '/' as necessary |
|---|
| 624 | 623 | |
|---|
| 625 | 624 | ***********************************************************************/ |
|---|
| … | … | |
| 928 | 927 | { |
|---|
| 929 | 928 | FS.rename (cString, dst~'\0'); |
|---|
| 930 | | return this.set (dst); |
|---|
| | 929 | return this.set (dst, true); |
|---|
| 931 | 930 | } |
|---|
| 932 | 931 | |
|---|
| … | … | |
| 1359 | 1358 | fp = new FilePath(r"C:/foo/bar/test.bar"); |
|---|
| 1360 | 1359 | assert (fp.path == "C:/foo/bar/"); |
|---|
| 1361 | | fp = new FilePath(r"C:/foo/bar/test.bar"); |
|---|
| | 1360 | fp = new FilePath(r"C:\foo\bar\test.bar"); |
|---|
| 1362 | 1361 | assert (fp.path == r"C:/foo/bar/"); |
|---|
| 1363 | 1362 | |
|---|
| r3886 |
r3887 |
|
| 11 | 11 | A more direct route to the file-system than FilePath, but with |
|---|
| 12 | 12 | the potential overhead of heap activity. Use this if you don't |
|---|
| 13 | | need path editing or extraction features. For example, if all |
|---|
| 14 | | you want is to see if some path exists, using this module might |
|---|
| 15 | | be a more convenient option than FilePath: |
|---|
| | 13 | need path editing features. For example, if all you want is to |
|---|
| | 14 | see if some path exists, using this module would likely be more |
|---|
| | 15 | convenient than FilePath. For example: |
|---|
| 16 | 16 | --- |
|---|
| 17 | 17 | if (exists ("some/file/path")) |
|---|
| … | … | |
| 19 | 19 | --- |
|---|
| 20 | 20 | |
|---|
| 21 | | These functions can be less efficient than FilePath because they |
|---|
| | 21 | These functions may be less efficient than FilePath because they |
|---|
| 22 | 22 | may have to attach a null to the filename for each underlying O/S |
|---|
| 23 | 23 | call. Use Path when you need pedestrian access to the file-system, |
|---|
| 24 | | and are not manipulating the path components. Use FilePath for other |
|---|
| 25 | | scenarios. |
|---|
| | 24 | and are not manipulating the path components. Use FilePath where |
|---|
| | 25 | path editing or mutation is desired. |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | We encourage the use of "scoped import" with this module, such as |
|---|
| … | … | |
| 160 | 160 | static void exception (char[] filename) |
|---|
| 161 | 161 | { |
|---|
| 162 | | throw new IOException (filename[0..$-1] ~ ": " ~ SysError.lastMsg); |
|---|
| | 162 | exception (filename[0..$-1] ~ ": ", SysError.lastMsg); |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | /*********************************************************************** |
|---|
| | 166 | |
|---|
| | 167 | Throw an IO exception |
|---|
| | 168 | |
|---|
| | 169 | ***********************************************************************/ |
|---|
| | 170 | |
|---|
| | 171 | static void exception (char[] prefix, char[] error) |
|---|
| | 172 | { |
|---|
| | 173 | throw new IOException (prefix ~ error); |
|---|
| 163 | 174 | } |
|---|
| 164 | 175 | |
|---|
| … | … | |
| 904 | 915 | |
|---|
| 905 | 916 | Note that patterns of adjacent '.' separators are treated specially |
|---|
| 906 | | in that they will be assigned to the name instead of the suffix. In |
|---|
| 907 | | addition, a '.' at the start of a name signifies it does not belong |
|---|
| 908 | | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 917 | in that they will be assigned to the name where there is no distinct |
|---|
| | 918 | suffix. In addition, a '.' at the start of a name signifies it does |
|---|
| | 919 | not belong to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 920 | Patterns of intermediate '.' characters will otherwise be assigned |
|---|
| | 921 | to the suffix, such that "file....suffix" includes the dots within |
|---|
| | 922 | the suffix itself [see ext() for a suffix without dots]. |
|---|
| 909 | 923 | |
|---|
| 910 | 924 | Note also that normalization of path-separators occurs by default. |
|---|
| … | … | |
| 918 | 932 | package char[] fp; // filepath with trailing |
|---|
| 919 | 933 | package int end_, // before any trailing 0 |
|---|
| | 934 | ext_, // after rightmost '.' |
|---|
| 920 | 935 | name_, // file/dir name |
|---|
| 921 | 936 | folder_, // path before name |
|---|
| 922 | | suffix_; // after rightmost '.' |
|---|
| | 937 | suffix_; // including leftmost '.' |
|---|
| 923 | 938 | |
|---|
| 924 | 939 | /*********************************************************************** |
|---|
| … | … | |
| 1028 | 1043 | Ext is the tail of the filename, rightward of the rightmost |
|---|
| 1029 | 1044 | '.' separator e.g. path "foo.bar" has ext "bar". Note that |
|---|
| 1030 | | patterns of adjacent separators are treated specially; for |
|---|
| | 1045 | patterns of adjacent separators are treated specially - for |
|---|
| 1031 | 1046 | example, ".." will wind up with no ext at all |
|---|
| 1032 | 1047 | |
|---|
| … | … | |
| 1037 | 1052 | auto x = suffix; |
|---|
| 1038 | 1053 | if (x.length) |
|---|
| 1039 | | x = x [1..$]; |
|---|
| | 1054 | { |
|---|
| | 1055 | if (ext_ is 0) |
|---|
| | 1056 | foreach (c; x) |
|---|
| | 1057 | if (c is '.') |
|---|
| | 1058 | ++ext_; |
|---|
| | 1059 | else |
|---|
| | 1060 | break; |
|---|
| | 1061 | x = x [ext_ .. $]; |
|---|
| | 1062 | } |
|---|
| 1040 | 1063 | return x; |
|---|
| 1041 | 1064 | } |
|---|
| … | … | |
| 1151 | 1174 | break; |
|---|
| 1152 | 1175 | |
|---|
| | 1176 | // Windows file separators are illegal. Use |
|---|
| | 1177 | // standard() or equivalent to convert first |
|---|
| 1153 | 1178 | case '\\': |
|---|
| 1154 | | throw new IOException ("unexpected '\\' character in path: "~path); |
|---|
| | 1179 | FS.exception ("unexpected '\\' character in path: ", path); |
|---|
| 1155 | 1180 | |
|---|
| 1156 | 1181 | version (Win32) |
|---|
| r3886 |
r3887 |
|
| 16 | 16 | import tango.io.DeviceConduit : DeviceConduit; |
|---|
| 17 | 17 | import tango.io.FileConduit : FileConduit; |
|---|
| 18 | | import tango.io.FilePath : FilePath/*, PathView*/; |
|---|
| | 18 | import tango.io.FilePath : FilePath; |
|---|
| 19 | 19 | import tango.stdc.stringz : toStringz, toString16z; |
|---|
| 20 | 20 | |
|---|
| … | … | |
| 24 | 24 | version( Win32 ) |
|---|
| 25 | 25 | { |
|---|
| 26 | | import tango.sys.Common : DWORD, LONG; |
|---|
| | 26 | import tango.sys.Common : DWORD, LONG, MAX_PATH, PCHAR, CP_UTF8; |
|---|
| 27 | 27 | |
|---|
| 28 | 28 | enum : DWORD { FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000 } |
|---|
| … | … | |
| 39 | 39 | GetTempPathA, SetFilePointer, GetLastError, ERROR_SUCCESS; |
|---|
| 40 | 40 | |
|---|
| 41 | | HANDLE CreateFile(FilePath fn, DWORD da, DWORD sm, |
|---|
| | 41 | HANDLE CreateFile(char[] fn, DWORD da, DWORD sm, |
|---|
| 42 | 42 | LPSECURITY_ATTRIBUTES sa, DWORD cd, DWORD faa, HANDLE tf) |
|---|
| 43 | 43 | { |
|---|
| 44 | | return CreateFileA(fn.cString.ptr, da, sm, sa, cd, faa, tf); |
|---|
| | 44 | return CreateFileA(toStringz(fn), da, sm, sa, cd, faa, tf); |
|---|
| 45 | 45 | } |
|---|
| 46 | 46 | |
|---|
| … | … | |
| 61 | 61 | { |
|---|
| 62 | 62 | import tango.sys.Common : |
|---|
| | 63 | MultiByteToWideChar, WideCharToMultiByte, |
|---|
| 63 | 64 | GetVersionExW, OSVERSIONINFO, |
|---|
| 64 | 65 | CreateFileW, GENERIC_READ, GENERIC_WRITE, |
|---|
| … | … | |
| 69 | 70 | GetTempPathW, SetFilePointer, GetLastError, ERROR_SUCCESS; |
|---|
| 70 | 71 | |
|---|
| 71 | | import tango.text.convert.Utf : toString, toString16; |
|---|
| 72 | | |
|---|
| 73 | | HANDLE CreateFile(FilePath fn, DWORD da, DWORD sm, |
|---|
| | 72 | HANDLE CreateFile(char[] fn, DWORD da, DWORD sm, |
|---|
| 74 | 73 | LPSECURITY_ATTRIBUTES sa, DWORD cd, DWORD faa, HANDLE tf) |
|---|
| 75 | 74 | { |
|---|
| 76 | | return CreateFileW(toString16(fn.cString).ptr, |
|---|
| 77 | | da, sm, sa, cd, faa, tf); |
|---|
| | 75 | // convert into output buffer |
|---|
| | 76 | wchar[MAX_PATH+1] tmp = void; |
|---|
| | 77 | assert (fn.length < tmp.length); |
|---|
| | 78 | auto i = MultiByteToWideChar (CP_UTF8, 0, cast(PCHAR) fn.ptr, |
|---|
| | 79 | fn.length, tmp.ptr, tmp.length); |
|---|
| | 80 | tmp[i] = 0; |
|---|
| | 81 | return CreateFileW(tmp.ptr, da, sm, sa, cd, faa, tf); |
|---|
| 78 | 82 | } |
|---|
| 79 | 83 | |
|---|
| … | … | |
| 88 | 92 | if( len == 0 ) |
|---|
| 89 | 93 | throw new Exception("could not obtain temporary path"); |
|---|
| 90 | | return Path.standard(toString(result[0..len])); |
|---|
| | 94 | |
|---|
| | 95 | auto dir = new char [len * 3]; |
|---|
| | 96 | auto i = WideCharToMultiByte (CP_UTF8, 0, result.ptr, len, |
|---|
| | 97 | cast(PCHAR) dir.ptr, dir.length, null, null); |
|---|
| | 98 | return Path.standard (dir[0..i]); |
|---|
| 91 | 99 | } |
|---|
| 92 | 100 | } |
|---|
| … | … | |
| 286 | 294 | |
|---|
| 287 | 295 | // Path to the temporary file |
|---|
| 288 | | private /*PathView*/ FilePath _path; |
|---|
| | 296 | private char[] _path; |
|---|
| 289 | 297 | |
|---|
| 290 | 298 | // Style we've opened with |
|---|
| … | … | |
| 303 | 311 | this(char[] prefix, Style style = Style.init) |
|---|
| 304 | 312 | { |
|---|
| 305 | | this(FilePath(prefix), style); |
|---|
| 306 | | } |
|---|
| 307 | | |
|---|
| 308 | | /// |
|---|
| 309 | | this(FilePath prefix, Style style = Style.init) |
|---|
| 310 | | { |
|---|
| 311 | | create(prefix.dup, style); |
|---|
| | 313 | create (prefix, style); |
|---|
| | 314 | } |
|---|
| | 315 | |
|---|
| | 316 | /// deprecated: please use char[] version instead |
|---|
| | 317 | deprecated this(FilePath prefix, Style style = Style.init) |
|---|
| | 318 | { |
|---|
| | 319 | this (prefix.toString.dup, style); |
|---|
| 312 | 320 | } |
|---|
| 313 | 321 | |
|---|
| … | … | |
| 319 | 327 | /************************************************************************** |
|---|
| 320 | 328 | * |
|---|
| 321 | | * Returns a PathView to the temporary file. Please note that depending |
|---|
| | 329 | * Returns the path of the temporary file. Please note that depending |
|---|
| 322 | 330 | * on your platform, the returned path may or may not actually exist if |
|---|
| 323 | 331 | * you specified a transient file. |
|---|
| 324 | 332 | * |
|---|
| 325 | 333 | **************************************************************************/ |
|---|
| 326 | | /*PathView*/ FilePath path() |
|---|
| | 334 | char[] path() |
|---|
| 327 | 335 | { |
|---|
| 328 | 336 | return _path; |
|---|
| … | … | |
| 341 | 349 | override char[] toString() |
|---|
| 342 | 350 | { |
|---|
| 343 | | if( path.toString.length > 0 ) |
|---|
| 344 | | return path.toString; |
|---|
| | 351 | if( path.length > 0 ) |
|---|
| | 352 | return path; |
|---|
| 345 | 353 | else |
|---|
| 346 | 354 | return "<TempFile>"; |
|---|
| … | … | |
| 379 | 387 | } |
|---|
| 380 | 388 | |
|---|
| 381 | | private void create(FilePath prefix, Style style) |
|---|
| | 389 | private void create(char[] prefix, Style style) |
|---|
| 382 | 390 | { |
|---|
| 383 | 391 | for( size_t i=0; i<style.attempts; ++i ) |
|---|
| 384 | 392 | { |
|---|
| 385 | | if( create_path(prefix.dup.append(randomName), style) ) |
|---|
| | 393 | if( create_path(Path.join(prefix, randomName), style) ) |
|---|
| 386 | 394 | return; |
|---|
| 387 | 395 | } |
|---|
| … | … | |
| 402 | 410 | * Returns the path to the temporary directory. |
|---|
| 403 | 411 | */ |
|---|
| 404 | | public static FilePath tempPath() |
|---|
| 405 | | { |
|---|
| 406 | | return FilePath(GetTempPath()).dup; |
|---|
| | 412 | public static char[] tempPath() |
|---|
| | 413 | { |
|---|
| | 414 | return GetTempPath; |
|---|
| 407 | 415 | } |
|---|
| 408 | 416 | |
|---|
| … | … | |
| 411 | 419 | * style. |
|---|
| 412 | 420 | */ |
|---|
| 413 | | private bool create_path(FilePath path, Style style) |
|---|
| | 421 | private bool create_path(char[] path, Style style) |
|---|
| 414 | 422 | { |
|---|
| 415 | 423 | // TODO: Check permissions directly and throw an exception; |
|---|
| … | … | |
| 480 | 488 | * Returns the path to the temporary directory. |
|---|
| 481 | 489 | */ |
|---|
| 482 | | public static FilePath tempPath() |
|---|
| | 490 | public static char[] tempPath() |
|---|
| 483 | 491 | { |
|---|
| 484 | 492 | // Check for TMPDIR; failing that, use /tmp |
|---|
| 485 | 493 | if( auto tmpdir = Environment.get("TMPDIR") ) |
|---|
| 486 | | return FilePath(tmpdir).dup; |
|---|
| | 494 | return tmpdir.dup; |
|---|
| 487 | 495 | else |
|---|
| 488 | | return FilePath("/tmp/").dup; |
|---|
| | 496 | return "/tmp/"; |
|---|
| 489 | 497 | } |
|---|
| 490 | 498 | |
|---|
| … | … | |
| 493 | 501 | * style. |
|---|
| 494 | 502 | */ |
|---|
| 495 | | private bool create_path(FilePath path, Style style) |
|---|
| | 503 | private bool create_path(char[] path, Style style) |
|---|
| 496 | 504 | { |
|---|
| 497 | 505 | // Check suitability |
|---|
| 498 | 506 | { |
|---|
| 499 | | auto parent = path.path; |
|---|
| | 507 | auto parent = Path.parse(path).path; |
|---|
| 500 | 508 | auto parentz = toStringz(parent); |
|---|
| 501 | 509 | |
|---|
| … | … | |
| 528 | 536 | | O_NOFOLLOW | O_RDWR; |
|---|
| 529 | 537 | |
|---|
| 530 | | auto pathz = path.cString.ptr; |
|---|
| | 538 | auto pathz = toStringz(path); |
|---|
| 531 | 539 | |
|---|
| 532 | 540 | handle = open(pathz, flags, 0600); |
|---|
| … | … | |
| 579 | 587 | * |
|---|
| 580 | 588 | **********************************************************************/ |
|---|
| 581 | | FilePath tempPath(); |
|---|
| | 589 | char[] tempPath(); |
|---|
| 582 | 590 | } |
|---|
| 583 | 591 | else |
|---|
| r3724 |
r3887 |
|
| 13 | 13 | private import tango.core.Exception; |
|---|
| 14 | 14 | |
|---|
| 15 | | public import tango.io.model.IConduit; |
|---|
| | 15 | public import tango.io.Conduit; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | /** |
|---|
| … | … | |
| 36 | 36 | * t.join(); |
|---|
| 37 | 37 | */ |
|---|
| 38 | | class ThreadConduit : IConduit |
|---|
| | 38 | class ThreadConduit : Conduit |
|---|
| 39 | 39 | { |
|---|
| 40 | 40 | private bool _closed; |
|---|
| … | … | |
| 60 | 60 | |
|---|
| 61 | 61 | /** |
|---|
| 62 | | * Implements IConduit.input (covariant) |
|---|
| 63 | | */ |
|---|
| 64 | | ThreadConduit input() |
|---|
| 65 | | { |
|---|
| 66 | | return this; |
|---|
| 67 | | } |
|---|
| 68 | | |
|---|
| 69 | | /** |
|---|
| 70 | | * Implements IConduit.output (covariant) |
|---|
| 71 | | */ |
|---|
| 72 | | ThreadConduit output() |
|---|
| 73 | | { |
|---|
| 74 | | return this; |
|---|
| 75 | | } |
|---|
| 76 | | |
|---|
| 77 | | /** |
|---|
| 78 | 62 | * Implements IConduit.bufferSize |
|---|
| 79 | 63 | * |
|---|
| … | … | |
| 91 | 75 | * Implements IConduit.toString |
|---|
| 92 | 76 | * |
|---|
| 93 | | * Returns "<thread conduit>" |
|---|
| | 77 | * Returns "<thread conduit>" |
|---|
| 94 | 78 | */ |
|---|
| 95 | 79 | char[] toString() |
|---|
| … | … | |
| 102 | 86 | * closed. |
|---|
| 103 | 87 | */ |
|---|
| 104 | | bool isAlive() |
|---|
| | 88 | override bool isAlive() |
|---|
| 105 | 89 | { |
|---|
| 106 | 90 | synchronized(_mutex) |
|---|
| … | … | |
| 152 | 136 | _condition.notifyAll(); |
|---|
| 153 | 137 | } |
|---|
| 154 | | } |
|---|
| 155 | | |
|---|
| 156 | | /** |
|---|
| 157 | | * Throw an IOException with the given message. |
|---|
| 158 | | */ |
|---|
| 159 | | void error(char[] msg) |
|---|
| 160 | | { |
|---|
| 161 | | throw new IOException(msg); |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | /** |
|---|
| 165 | | * Implements InputStream.conduit and OutputStream.conduit (covariant) |
|---|
| 166 | | */ |
|---|
| 167 | | ThreadConduit conduit() |
|---|
| 168 | | { |
|---|
| 169 | | return this; |
|---|
| 170 | | } |
|---|
| 171 | | |
|---|
| 172 | | /** |
|---|
| 173 | | * Close the write end of the conduit. Same as detach() |
|---|
| 174 | | */ |
|---|
| 175 | | void close() |
|---|
| 176 | | { |
|---|
| 177 | | detach(); |
|---|
| 178 | 138 | } |
|---|
| 179 | 139 | |
|---|
| … | … | |
| 230 | 190 | return result; |
|---|
| 231 | 191 | } |
|---|
| 232 | | } |
|---|
| 233 | | |
|---|
| 234 | | /** |
|---|
| 235 | | * Implements InputStream.load |
|---|
| 236 | | * |
|---|
| 237 | | * Load the bits from a stream, and return them all in an array. The dst |
|---|
| 238 | | * array can be provided as an option, which will be expanded as necessary |
|---|
| 239 | | * to consume the input. |
|---|
| 240 | | * |
|---|
| 241 | | * Returns an array representing the content, and throws IOException on |
|---|
| 242 | | * error |
|---|
| 243 | | */ |
|---|
| 244 | | void[] load(void[] dst = null) |
|---|
| 245 | | { |
|---|
| 246 | | // |
|---|
| 247 | | // copied from Conduit.load |
|---|
| 248 | | // |
|---|
| 249 | | auto chunk = 0; |
|---|
| 250 | | auto index = 0; |
|---|
| 251 | | |
|---|
| 252 | | while (chunk != Eof) |
|---|
| 253 | | { |
|---|
| 254 | | if (dst.length - index < 1024) |
|---|
| 255 | | dst.length = dst.length + 16 * 1024; |
|---|
| 256 | | |
|---|
| 257 | | chunk = read (dst[index .. $]); |
|---|
| 258 | | index += chunk; |
|---|
| 259 | | } |
|---|
| 260 | | |
|---|
| 261 | | return dst [0 .. index - chunk]; |
|---|
| 262 | 192 | } |
|---|
| 263 | 193 | |
|---|
| … | … | |
| 325 | 255 | } |
|---|
| 326 | 256 | } |
|---|
| 327 | | |
|---|
| 328 | | /** |
|---|
| 329 | | * Implements OutputStream.copy |
|---|
| 330 | | * |
|---|
| 331 | | * Transfer the content of another stream to this one. Returns a reference |
|---|
| 332 | | * to this class, and throws IOException on failure. |
|---|
| 333 | | */ |
|---|
| 334 | | ThreadConduit copy(InputStream src) |
|---|
| 335 | | { |
|---|
| 336 | | // |
|---|
| 337 | | // copied from Conduit |
|---|
| 338 | | // |
|---|
| 339 | | uint len = 0; |
|---|
| 340 | | auto tmp = new void [bufferSize]; |
|---|
| 341 | | while ((len = src.read(tmp)) != IConduit.Eof) |
|---|
| 342 | | { |
|---|
| 343 | | auto p = tmp.ptr; |
|---|
| 344 | | for (uint j; len > 0; len -= j, p += j) |
|---|
| 345 | | if ((j = write (p[0..len])) is IConduit.Eof) |
|---|
| 346 | | error ("ThreadConduit.copy :: Eof while writing to: "~toString); |
|---|
| 347 | | } |
|---|
| 348 | | delete tmp; |
|---|
| 349 | | return this; |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | /** |
|---|
| 353 | | * Implements OutputStream.flush |
|---|
| 354 | | * |
|---|
| 355 | | * Since there is no callable sink, this is a noop. |
|---|
| 356 | | */ |
|---|
| 357 | | ThreadConduit flush() |
|---|
| 358 | | { |
|---|
| 359 | | return this; |
|---|
| 360 | | } |
|---|
| 361 | 257 | } |
|---|
| r3886 |
r3887 |
|
| 1522 | 1522 | with( info ) |
|---|
| 1523 | 1523 | { |
|---|
| 1524 | | name = header.file_name.dup; |
|---|
| | 1524 | name = Path.standard(header.file_name.dup); |
|---|
| 1525 | 1525 | dosToTime(header.data.modification_file_time, |
|---|
| 1526 | 1526 | header.data.modification_file_date, |
|---|
| r2810 |
r3887 |
|
| 47 | 47 | for (int j = 8; j > 0; j--) |
|---|
| 48 | 48 | { |
|---|
| | 49 | version (Gim) |
|---|
| | 50 | { |
|---|
| | 51 | if (value & 1) |
|---|
| | 52 | { |
|---|
| | 53 | value >>>= 1; |
|---|
| | 54 | value ^= polynomial; |
|---|
| | 55 | } |
|---|
| | 56 | else |
|---|
| | 57 | value >>>= 1; |
|---|
| | 58 | } |
|---|
| | 59 | else |
|---|
| | 60 | { |
|---|
| 49 | 61 | if (value & 1) { |
|---|
| 50 | 62 | value &= 0xFFFFFFFE; |
|---|
| … | … | |
| 59 | 71 | value &= 0x7FFFFFFF; |
|---|
| 60 | 72 | } |
|---|
| | 73 | } |
|---|
| 61 | 74 | } |
|---|
| 62 | 75 | table[i] = value; |
|---|
| … | … | |
| 65 | 78 | |
|---|
| 66 | 79 | /** */ |
|---|
| 67 | | override void update (void[] input) |
|---|
| | 80 | override Crc32 update (void[] input) |
|---|
| 68 | 81 | { |
|---|
| 69 | 82 | uint r = result; // DMD optimization |
|---|
| … | … | |
| 72 | 85 | auto i = cast(ubyte) r;// & 0xff; |
|---|
| 73 | 86 | i ^= value; |
|---|
| | 87 | version (Gim) |
|---|
| | 88 | { |
|---|
| | 89 | r >>>= 8; |
|---|
| | 90 | } |
|---|
| | 91 | else |
|---|
| | 92 | &n |
|---|
|