From 48f591567762aeafa8aa21c3ee355a0506ce07ee Mon Sep 17 00:00:00 2001 From: Dmitry Olshansky Date: Thu, 15 Mar 2012 13:25:33 +0400 Subject: [PATCH 1/2] fix Issue 7138 - Can't call array() on dirEntries Alias this now appears to work properly, hence all tricks & problems with dual opDispatch are removed. Also fixes: Issue 7264 - Can't iterate result from 4-arg dirEntries as string --- std/datetime.d | 2 +- std/file.d | 63 +++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/std/datetime.d b/std/datetime.d index b6813742b..190f78597 100644 --- a/std/datetime.d +++ b/std/datetime.d @@ -31169,7 +31169,7 @@ version(testStdDateTime) unittest Returns a $(D d_time) for the given $(D SysTime). +/ -deprecated long sysTimeToDTime(in SysTime sysTime) +deprecated long sysTimeToDTime(in SysTime sysTime) pure nothrow { return convert!("hnsecs", "msecs")(sysTime.stdTime - 621355968000000000L); } diff --git a/std/file.d b/std/file.d index 4edefd8bb..ebef8b906 100644 --- a/std/file.d +++ b/std/file.d @@ -2102,20 +2102,21 @@ else version(Windows) struct DirEntry { public: + alias name this; - @property string name() const + @property string name() const pure nothrow { return _name; } - @property bool isDir() const + @property bool isDir() const pure nothrow { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; } deprecated alias isDir isdir; - @property bool isFile() const + @property bool isFile() const pure nothrow { //Are there no options in Windows other than directory and file? //If there are, then this probably isn't the best way to determine @@ -2125,52 +2126,52 @@ else version(Windows) deprecated alias isFile isfile; - @property bool isSymlink() const + @property bool isSymlink() const pure nothrow { return (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0; } - @property ulong size() const + @property ulong size() const pure nothrow { return _size; } - deprecated @property d_time creationTime() const + deprecated @property d_time creationTime() const pure nothrow { return sysTimeToDTime(_timeCreated); } - @property SysTime timeCreated() const + @property SysTime timeCreated() const pure nothrow { return cast(SysTime)_timeCreated; } - deprecated @property d_time lastAccessTime() const + deprecated @property d_time lastAccessTime() const pure nothrow { return sysTimeToDTime(_timeLastAccessed); } - @property SysTime timeLastAccessed() const + @property SysTime timeLastAccessed() const pure nothrow { return cast(SysTime)_timeLastAccessed; } - deprecated @property d_time lastWriteTime() const + deprecated @property d_time lastWriteTime() const pure nothrow { return sysTimeToDTime(_timeLastModified); } - @property SysTime timeLastModified() const + @property SysTime timeLastModified() const pure nothrow { return cast(SysTime)_timeLastModified; } - @property uint attributes() const + @property uint attributes() const pure nothrow { return _attributes; } - @property uint linkAttributes() const + @property uint linkAttributes() const pure nothrow { return _attributes; } @@ -2246,8 +2247,9 @@ else version(Posix) struct DirEntry { public: + alias name this; - @property string name() const + @property string name() const pure nothrow { return _name; } @@ -3082,23 +3084,7 @@ public: @property bool empty(){ return impl.empty; } @property DirEntry front(){ return impl.front; } void popFront(){ impl.popFront(); } - int opApply(int delegate(ref string name) dg) - { - foreach(DirEntry v; impl.refCountedPayload) - { - string s = v.name; - if(dg(s)) - return 1; - } - return 0; - } - int opApply(int delegate(ref DirEntry name) dg) - { - foreach(DirEntry v; impl.refCountedPayload) - if(dg(v)) - return 1; - return 0; - } + } /++ Returns an input range of DirEntry that lazily iterates a given directory, @@ -3189,6 +3175,21 @@ unittest } } +unittest +{ + //issue 7264 + foreach (string name; dirEntries(".", "*.d", SpanMode.breadth)) + { + + } + foreach (entry; dirEntries(".", SpanMode.breadth)) + { + static assert(is(typeof(entry) == DirEntry)); + } + //issue 7138 + auto a = array(dirEntries(".", SpanMode.shallow)); +} + /++ Convenience wrapper for filtering file names with a glob pattern. From e25d430b99a28bfb60aaa6efb24e5175b0abb829 Mon Sep 17 00:00:00 2001 From: Dmitry Olshansky Date: Thu, 15 Mar 2012 17:36:14 +0400 Subject: [PATCH 2/2] revert changes to deprecated stuff --- std/datetime.d | 2 +- std/file.d | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/std/datetime.d b/std/datetime.d index 190f78597..b6813742b 100644 --- a/std/datetime.d +++ b/std/datetime.d @@ -31169,7 +31169,7 @@ version(testStdDateTime) unittest Returns a $(D d_time) for the given $(D SysTime). +/ -deprecated long sysTimeToDTime(in SysTime sysTime) pure nothrow +deprecated long sysTimeToDTime(in SysTime sysTime) { return convert!("hnsecs", "msecs")(sysTime.stdTime - 621355968000000000L); } diff --git a/std/file.d b/std/file.d index ebef8b906..c1341d6a4 100644 --- a/std/file.d +++ b/std/file.d @@ -2136,7 +2136,7 @@ else version(Windows) return _size; } - deprecated @property d_time creationTime() const pure nothrow + deprecated @property d_time creationTime() const { return sysTimeToDTime(_timeCreated); } @@ -2146,7 +2146,7 @@ else version(Windows) return cast(SysTime)_timeCreated; } - deprecated @property d_time lastAccessTime() const pure nothrow + deprecated @property d_time lastAccessTime() const { return sysTimeToDTime(_timeLastAccessed); } @@ -2156,7 +2156,7 @@ else version(Windows) return cast(SysTime)_timeLastAccessed; } - deprecated @property d_time lastWriteTime() const pure nothrow + deprecated @property d_time lastWriteTime() const { return sysTimeToDTime(_timeLastModified); }