diff --git a/source/dub/init.d b/source/dub/init.d index f0f8d2e..90893f0 100644 --- a/source/dub/init.d +++ b/source/dub/init.d @@ -9,7 +9,7 @@ import dub.internal.vibecompat.core.file; import dub.internal.vibecompat.core.log; -import dub.package_ : packageInfoFilenames; +import dub.package_ : packageInfoFilenames, defaultPackageFilename; import std.datetime; import std.exception; @@ -89,7 +89,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 ~ defaultPackageFilename(), FileMode.Append); scope(exit) fil.close(); fil.formattedWrite("{\n\t\"name\": \"%s\",\n", root_path.head.toString().toLower()); diff --git a/source/dub/package_.d b/source/dub/package_.d index f3542ac..d9cc2a3 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -25,12 +25,16 @@ import std.traits : EnumMembers; +// Supported package descriptions in decreasing order of preference. enum packageInfoFilenames = ["dub.json", /*"dub.sdl",*/ "package.json"]; +string defaultPackageFilename() { + return packageInfoFilenames[0]; +} /** Represents a package, including its sub packages - Documentation of the package.json can be found at + Documentation of the dub.json can be found at http://registry.vibed.org/package-format */ class Package { @@ -56,13 +60,15 @@ this(Path root, Package parent = null) { Json info; - if (existsFile(root ~ "dub.json")) { - m_infoFile = root ~ "dub.json"; - info = jsonFromFile(m_infoFile); - } else if (existsFile(root ~ "package.json")) { - m_infoFile = root ~ "package.json"; - info = jsonFromFile(root ~ "package.json"); - } else { + foreach (f; packageInfoFilenames) { + auto name = root ~ f; + if (existsFile(name)) { + m_infoFile = name; + info = jsonFromFile(m_infoFile); + break; + } + } + if (info == Json.undefined) { throw new Exception("Missing package description for package in %s", root.toNativeString()); } this(info, root, parent); @@ -202,13 +208,15 @@ return ret.data; } - /** Overwrites the packge description file with the current information. + /** Overwrites the packge description file using the default filename with the current information. */ void storeInfo() { - auto dstFile = openFile((m_path ~ "dub.json").toString(), FileMode.CreateTrunc); + auto filename = m_path ~ defaultPackageFilename(); + auto dstFile = openFile(filename.toNativeString(), FileMode.CreateTrunc); scope(exit) dstFile.close(); dstFile.writePrettyJsonString(m_info.toJson()); + m_infoFile = filename; } inout(Package) getSubPackage(string name) inout { diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 4ac0267..df0bce8 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -272,6 +272,13 @@ // overwrite package.json (this one includes a version field) auto pack = new Package(destination); pack.info.version_ = package_info["version"].get!string; + + if (pack.packageInfoFile.head != defaultPackageFilename()) { + // Storeinfo saved a default file, this could be different to the file from the zip. + removeFile(pack.packageInfoFile); + journal.remove(Journal.Entry(Journal.Type.RegularFile, pack.packageInfoFile)); + journal.add(Journal.Entry(Journal.Type.RegularFile, destination ~ Path(defaultPackageFilename()))); + } pack.storeInfo(); // Write journal @@ -362,13 +369,13 @@ Package addLocalPackage(in Path path, string verName, LocalPackageType type) { - Package[]* packs = &m_repositories[type].localPackages; - auto pack = new Package(path); + enforce(pack.name.length, "The package has no name, defined in: " ~ path.toString()); if (verName.length) pack.ver = Version(verName); // don't double-add packages + Package[]* packs = &m_repositories[type].localPackages; foreach (p; *packs) { if (p.path == path) { enforce(p.ver == pack.ver, "Adding the same local package twice with differing versions is not allowed."); @@ -415,6 +422,7 @@ } auto pack = new Package(path); + enforce(pack.name.length, "The package has no name, defined in: " ~ path.toString()); pack.ver = ver; addPackages(m_temporaryPackages, pack); return pack; @@ -651,7 +659,7 @@ m_entries ~= Entry(to!Type(cast(string)type), Path(file)); } - void add(Entry e) { + void add(Entry e) { foreach(Entry ent; entries) { if( e.relFilename == ent.relFilename ) { enforce(e.type == ent.type, "Duplicate('"~to!string(e.relFilename)~"'), different types: "~to!string(e.type)~" vs. "~to!string(ent.type)); @@ -660,6 +668,16 @@ } m_entries ~= e; } + + void remove(Entry e) { + foreach(i, Entry ent; entries) { + if( e.relFilename == ent.relFilename ) { + m_entries = std.algorithm.remove(m_entries, i); + return; + } + } + enforce(false, "Cannot remove entry, not available: " ~ e.relFilename.toNativeString()); + } /// Save the current state to the path. void save(Path path) { diff --git a/source/dub/project.d b/source/dub/project.d index 8eb7d7a..102a53b 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -474,7 +474,7 @@ // Gather retrieved Package[string] retrieved; retrieved[m_main.name] = m_main; - foreach(dep, ref Package p; m_dependencies) { + foreach(ref Package p; m_dependencies) { auto pbase = p.basePackage; auto pexist = retrieved.get(pbase.name, null); if (pexist && pexist !is pbase){