diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index 32ffae3..1b70692 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -402,7 +402,7 @@ auto path = getTempFile("dub_platform_probe", ".d"); - auto fil = openFile(path, FileMode.CreateTrunc); + auto fil = openFile(path, FileMode.createTrunc); scope (failure) { fil.close(); } diff --git a/source/dub/dub.d b/source/dub/dub.d index 3d8286c..222a7a5 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -372,7 +372,7 @@ tcinfo.sourceFiles[""] ~= mainfile.toNativeString(); tcinfo.mainSourceFile = mainfile.toNativeString(); if (!m_dryRun) { - auto fil = openFile(mainfile, FileMode.CreateTrunc); + auto fil = openFile(mainfile, FileMode.createTrunc); scope(exit) fil.close(); fil.write("module dub_test_root;\n"); fil.write("import std.typetuple;\n"); diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index bc8285a..cfec31d 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -121,7 +121,7 @@ // Writing solution file logDebug("About to write to .sln file with %s bytes", to!string(ret.data.length)); - auto sln = openFile(solutionFileName(), FileMode.CreateTrunc); + auto sln = openFile(solutionFileName(), FileMode.createTrunc); scope(exit) sln.close(); sln.put(ret.data); sln.flush(); @@ -227,7 +227,7 @@ ret.put("\n \n"); logDebug("About to write to '%s.visualdproj' file %s bytes", getPackageFileName(packname), ret.data.length); - auto proj = openFile(projFileName(packname), FileMode.CreateTrunc); + auto proj = openFile(projFileName(packname), FileMode.createTrunc); scope(exit) proj.close(); proj.put(ret.data); proj.flush(); diff --git a/source/dub/init.d b/source/dub/init.d index 1e09c0c..75f1279 100644 --- a/source/dub/init.d +++ b/source/dub/init.d @@ -125,7 +125,7 @@ version (Windows) username = environment.get("USERNAME", "Peter Parker"); else username = environment.get("USER", "Peter Parker"); - auto fil = openFile(root_path ~ "dub.json", FileMode.Append); + auto fil = openFile(root_path ~ "dub.json", FileMode.append); scope(exit) fil.close(); fil.formattedWrite("{\n\t\"name\": \"%s\",\n", root_path.head.toString().toLower()); @@ -149,7 +149,7 @@ version (Windows) username = environment.get("USERNAME", "Peter Parker"); else username = environment.get("USER", "Peter Parker"); - auto fil = openFile(root_path ~ "dub.sdl", FileMode.Append); + auto fil = openFile(root_path ~ "dub.sdl", FileMode.append); scope(exit) fil.close(); fil.formattedWrite("name \"%s\"\n", root_path.head.toString().toLower()); diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index 9692d9a..b55b54b 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -62,7 +62,7 @@ import std.random; auto fname = p ~ format("__dub_write_test_%08X", uniform(0, uint.max)); if (create_if_missing && !exists(p.toNativeString())) mkdirRecurse(p.toNativeString()); - try openFile(fname, FileMode.CreateTrunc).close(); + try openFile(fname, FileMode.createTrunc).close(); catch (Exception) return false; remove(fname.toNativeString()); return true; @@ -70,14 +70,14 @@ Json jsonFromFile(Path file, bool silent_fail = false) { if( silent_fail && !existsFile(file) ) return Json.emptyObject; - auto f = openFile(file.toNativeString(), FileMode.Read); + auto f = openFile(file.toNativeString(), FileMode.read); scope(exit) f.close(); auto text = stripUTF8Bom(cast(string)f.readAll()); return parseJsonString(text, file.toNativeString()); } Json jsonFromZip(Path zip, string filename) { - auto f = openFile(zip, FileMode.Read); + auto f = openFile(zip, FileMode.read); ubyte[] b = new ubyte[cast(size_t)f.size]; f.rawRead(b); f.close(); @@ -88,7 +88,7 @@ void writeJsonFile(Path path, Json json) { - auto f = openFile(path, FileMode.CreateTrunc); + auto f = openFile(path, FileMode.createTrunc); scope(exit) f.close(); f.writePrettyJsonString(json); } diff --git a/source/dub/internal/vibecompat/core/file.d b/source/dub/internal/vibecompat/core/file.d index 1ca6a25..3d47548 100644 --- a/source/dub/internal/vibecompat/core/file.d +++ b/source/dub/internal/vibecompat/core/file.d @@ -54,21 +54,21 @@ /** Opens a file stream with the specified mode. */ -RangeFile openFile(Path path, FileMode mode = FileMode.Read) +RangeFile openFile(Path path, FileMode mode = FileMode.read) { std.stream.FileMode fmode; final switch(mode){ - case FileMode.Read: fmode = std.stream.FileMode.In; break; - case FileMode.ReadWrite: fmode = std.stream.FileMode.Out; break; - case FileMode.CreateTrunc: fmode = std.stream.FileMode.OutNew; break; - case FileMode.Append: fmode = std.stream.FileMode.Append; break; + case FileMode.read: fmode = std.stream.FileMode.In; break; + case FileMode.readWrite: fmode = std.stream.FileMode.Out; break; + case FileMode.createTrunc: fmode = std.stream.FileMode.OutNew; break; + case FileMode.append: fmode = std.stream.FileMode.Append; break; } auto ret = new std.stream.File(path.toNativeString(), fmode); assert(ret.isOpen); return RangeFile(ret); } /// ditto -RangeFile openFile(string path, FileMode mode = FileMode.Read) +RangeFile openFile(string path, FileMode mode = FileMode.read) { return openFile(Path(path), mode); } @@ -298,13 +298,13 @@ */ enum FileMode { /// The file is opened read-only. - Read, + read, /// The file is opened for read-write random access. - ReadWrite, + readWrite, /// The file is truncated if it exists and created otherwise and the opened for read-write access. - CreateTrunc, + createTrunc, /// The file is opened for appending data to it and created if it does not exist. - Append + append } /** diff --git a/source/dub/package_.d b/source/dub/package_.d index 45e4db2..2f06e15 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -31,25 +31,30 @@ import std.typecons : Nullable; +enum PackageFormat { + json, + sdl +} -enum PackageFormat { json, sdl } -struct FilenameAndFormat -{ +struct FilenameAndFormat { string filename; PackageFormat format; } -struct PathAndFormat -{ + +struct PathAndFormat { Path path; PackageFormat format; + @property bool empty() { return path.empty; } - string toString() { return path.toString(); } + + string toString() const { return path.toString(); } } + // Supported package descriptions in decreasing order of preference. static immutable FilenameAndFormat[] packageInfoFiles = [ {"dub.json", PackageFormat.json}, - {"dub.sdl",PackageFormat.sdl}, + {"dub.sdl", PackageFormat.sdl}, {"package.json", PackageFormat.json} ]; @@ -201,7 +206,7 @@ const { enforce(!ver.isUnknown, "Trying to store a package with an 'unknown' version, this is not supported."); auto filename = path ~ defaultPackageFilename; - auto dstFile = openFile(filename.toNativeString(), FileMode.CreateTrunc); + auto dstFile = openFile(filename.toNativeString(), FileMode.createTrunc); scope(exit) dstFile.close(); dstFile.writePrettyJsonString(m_info.toJson()); } @@ -517,7 +522,7 @@ string text; { - auto f = openFile(file.path.toNativeString(), FileMode.Read); + auto f = openFile(file.path.toNativeString(), FileMode.read); scope(exit) f.close(); text = stripUTF8Bom(cast(string)f.readAll()); } diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 34d34af..d062197 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -302,7 +302,7 @@ ZipArchive archive; { logDebug("Opening file %s", zip_file_path); - auto f = openFile(zip_file_path, FileMode.Read); + auto f = openFile(zip_file_path, FileMode.read); scope(exit) f.close(); archive = new ZipArchive(f.readAll()); } @@ -344,7 +344,7 @@ } else { if( !existsDirectory(dst_path.parentPath) ) mkdirRecurse(dst_path.parentPath.toNativeString()); - auto dstFile = openFile(dst_path, FileMode.CreateTrunc); + auto dstFile = openFile(dst_path, FileMode.createTrunc); scope(exit) dstFile.close(); dstFile.put(archive.expand(a)); ++countFiles; diff --git a/source/dub/project.d b/source/dub/project.d index 11733e3..a438953 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1006,7 +1006,7 @@ logDebug("writeDubJson"); auto dubpath = m_rootPackage.path~".dub"; if( !exists(dubpath.toNativeString()) ) mkdir(dubpath.toNativeString()); - auto dstFile = openFile((dubpath~"dub.json").toString(), FileMode.CreateTrunc); + auto dstFile = openFile((dubpath~"dub.json").toString(), FileMode.createTrunc); scope(exit) dstFile.close(); dstFile.writePrettyJsonString(m_packageSettings); } catch( Exception e ){ @@ -1291,7 +1291,7 @@ void save(Path path) { Json json = serialize(); - auto file = openFile(path, FileMode.CreateTrunc); + auto file = openFile(path, FileMode.createTrunc); scope(exit) file.close(); file.writePrettyJsonString(json); file.put('\n');