| ... | @@ -811,6 +811,17 @@ pub const IterableDir = struct { | ... | @@ -811,6 +811,17 @@ pub const IterableDir = struct { |
| 811 | }; | 811 | }; |
| 812 | | 812 | |
| 813 | pub fn iterate(self: IterableDir) Iterator { | 813 | pub fn iterate(self: IterableDir) Iterator { |
| | 814 | return self.iterateImpl(true); |
| | 815 | } |
| | 816 | |
| | 817 | /// Like `iterate`, but will not reset the directory cursor before the first |
| | 818 | /// iteration. This should only be used in cases where it is known that the |
| | 819 | /// `IterableDir` has not had its cursor modified yet (e.g. it was just opened). |
| | 820 | pub fn iterateAssumeFirstIteration(self: IterableDir) Iterator { |
| | 821 | return self.iterateImpl(false); |
| | 822 | } |
| | 823 | |
| | 824 | fn iterateImpl(self: IterableDir, first_iter_start_value: bool) Iterator { |
| 814 | switch (builtin.os.tag) { | 825 | switch (builtin.os.tag) { |
| 815 | .macos, | 826 | .macos, |
| 816 | .ios, | 827 | .ios, |
| ... | @@ -825,20 +836,20 @@ pub const IterableDir = struct { | ... | @@ -825,20 +836,20 @@ pub const IterableDir = struct { |
| 825 | .index = 0, | 836 | .index = 0, |
| 826 | .end_index = 0, | 837 | .end_index = 0, |
| 827 | .buf = undefined, | 838 | .buf = undefined, |
| 828 | .first_iter = true, | 839 | .first_iter = first_iter_start_value, |
| 829 | }, | 840 | }, |
| 830 | .linux, .haiku => return Iterator{ | 841 | .linux, .haiku => return Iterator{ |
| 831 | .dir = self.dir, | 842 | .dir = self.dir, |
| 832 | .index = 0, | 843 | .index = 0, |
| 833 | .end_index = 0, | 844 | .end_index = 0, |
| 834 | .buf = undefined, | 845 | .buf = undefined, |
| 835 | .first_iter = true, | 846 | .first_iter = first_iter_start_value, |
| 836 | }, | 847 | }, |
| 837 | .windows => return Iterator{ | 848 | .windows => return Iterator{ |
| 838 | .dir = self.dir, | 849 | .dir = self.dir, |
| 839 | .index = 0, | 850 | .index = 0, |
| 840 | .end_index = 0, | 851 | .end_index = 0, |
| 841 | .first_iter = true, | 852 | .first_iter = first_iter_start_value, |
| 842 | .buf = undefined, | 853 | .buf = undefined, |
| 843 | .name_data = undefined, | 854 | .name_data = undefined, |
| 844 | }, | 855 | }, |