diff --git a/source/dub/package_.d b/source/dub/package_.d index 32d72c5..1c4105f 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -47,17 +47,17 @@ /// /// Json file example: /// { -/// "name": "MetalCollection", -/// "author": "VariousArtists", -/// "version": "1.0.0", +/// "name": "MetalCollection", +/// "author": "VariousArtists", +/// "version": "1.0.0", /// "url": "https://github.org/...", /// "keywords": "a,b,c", /// "category": "music.best", -/// "dependencies": { -/// "black-sabbath": ">=1.0.0", -/// "CowboysFromHell": "<1.0.0", -/// "BeneathTheRemains": {"version": "0.4.1", "path": "./beneath-0.4.1"} -/// } +/// "dependencies": { +/// "black-sabbath": ">=1.0.0", +/// "CowboysFromHell": "<1.0.0", +/// "BeneathTheRemains": {"version": "0.4.1", "path": "./beneath-0.4.1"} +/// } /// "licenses": { /// ... /// } diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 71aa3d6..62cf0a0 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -12,8 +12,9 @@ import dub.package_; import dub.utils; -import std.algorithm : countUntil, filter, sort; +import std.algorithm : countUntil, filter, sort, canFind; import std.conv; +import std.digest.sha; import std.exception; import std.file; import std.string; @@ -482,6 +483,36 @@ scanLocalPackages(m_userPackagePath, m_localUserPackages); } + alias ubyte[] Hash; + /// Generates a hash value for a given package. + /// Some files or folders are ignored during the generation (like .dub and + /// .svn folders) + Hash hashPackage(Package pack) + { + string[] ignored_directories = [".git", ".dub", ".svn"]; + // something from .dub_ignore or what? + string[] ignored_files = []; + SHA1 sha1; + foreach(file; dirEntries(pack.path.toNativeString(), SpanMode.depth)) { + if(file.isDir && ignored_directories.canFind(Path(file.name).head.toString())) + continue; + else if(ignored_files.canFind(Path(file.name).head.toString())) + continue; + + sha1.put(cast(ubyte[])Path(file.name).head.toString()); + if(file.isDir) { + logTrace("Hashed directory name %s", Path(file.name).head); + } + else { + sha1.put(openFile(Path(file.name)).readAll()); + logTrace("Hashed file contents from %s", Path(file.name).head); + } + } + auto hash = sha1.finish(); + logTrace("Project hash: %s", hash); + return hash[0..$]; + } + private Package[]* getLocalPackageList(LocalPackageType type) { final switch(type){