1 module mecca.lib.paths;
2 
3 // Licensed under the Boost license. Full copyright information in the AUTHORS file
4 
5 
6 struct Path {
7     string _path;
8 
9     this(string path) {
10         _path = path;
11     }
12 
13     Path opBinary(string op: "/")(string rhs) {
14         return Path(_path ~ "/" ~ rhs);
15     }
16     Path opBinary(string op: "/")(Path rhs) {
17         return Path(_path ~ "/" ~ rhs);
18     }
19     Path opBinaryRight(string op: "/")(string lhs) {
20         return Path(lhs ~ "/" ~ _path);
21     }
22 
23     // stat, exists, isDir, isFile, isSymlink,
24     // unlink, link, symlink, copy, move, rename
25     // mkdir, rmdir(recurisve)
26     // write, read, open, touch
27     // dirname, basename, suffix (".exe")
28     // chown, chmod, access
29     // touch
30 
31     enum IterTypes {
32         ALL    = 0x00,
33         FILES  = 0x01,
34         DIRS   = 0x02,
35     }
36 
37     struct DirIter {
38         Path parent;
39         string globPattern;
40         IterTypes types;
41         // DIR* dir;
42 
43         this(Path parent, string globPattern, IterTypes types) {
44             this.parent = parent;
45             this.globPattern = globPattern;
46             this.types = types;
47         }
48 
49         @property bool empty() {
50             return true;
51         }
52         @property Path front() {
53             return Path.init;
54         }
55         void popFront() {
56         }
57     }
58 
59     DirIter iter(string globPattern=null, IterTypes types=IterTypes.ALL) {
60         return DirIter(this, globPattern, types);
61     }
62 }
63 
64 
65 unittest {
66     auto p1 = Path("/hello/world");
67     auto p2 = p1 / "zorld";
68     auto Sp3 = "/borld" / p1;
69 }
70 
71 
72 struct WorkDir {
73     private static __gshared Path path;
74 
75     @disable this();
76     @disable this(this);
77 
78     shared static this() {
79         // getcwd()
80     }
81 
82     @property Path get() nothrow {
83         return path;
84     }
85 
86     static void change(string newPath) {
87         change(Path(newPath));
88     }
89     static void change(Path newPath) {
90     }
91 
92     static auto push(string newPath) {
93         return push(Path(newPath));
94     }
95     static auto push(Path newPath) {
96         static struct Stacked {
97             private Path prev;
98             private this(Path prev, Path newPath) {
99                 this.prev = prev;
100                 WorkDir.change(newPath);
101             }
102             ~this() {
103                 WorkDir.change(prev);
104             }
105         }
106         return Stacked(path, newPath);
107     }
108 }
109 
110 
111 unittest {
112     with (WorkDir.push("/tmp")) {
113     }
114 }
115 
116 
117 
118 
119 
120 
121