diff --git a/source/VersionHandlerImpl/src/FileUtils.cs b/source/VersionHandlerImpl/src/FileUtils.cs index 6988dd63..5c1c9c2d 100644 --- a/source/VersionHandlerImpl/src/FileUtils.cs +++ b/source/VersionHandlerImpl/src/FileUtils.cs @@ -618,6 +618,22 @@ public static RemoveAssetsResult RemoveAssets(IEnumerable filenames, return result; } + /// + /// Check if a guid returned from Unity API is valid. + /// + /// GUID returned from Unity API. + /// True if the guid is valid. + internal static bool IsValidGuid(string guidStr) { + if(String.IsNullOrEmpty(guidStr)) return false; + try { + var guid = new Guid(guidStr); + if (guid == Guid.Empty) return false; + } catch (FormatException e) { + return false; + } + return true; + } + /// /// Recursively create all parent folders given a path. /// @@ -632,7 +648,15 @@ public static bool CreateFolder(string path) { if (!CreateFolder(parentFolder)) { return false; } - return !String.IsNullOrEmpty(AssetDatabase.CreateFolder(parentFolder, di.Name)); + + // Try to use Unity API to create folder. However, some versions of Unity has issue to + // create folders with version number in it like '9.0.0'. In this case, instead of + // returnig empty guid, it can return guids with all zeroes. + if (IsValidGuid(AssetDatabase.CreateFolder(parentFolder, di.Name))) { + return true; + } + + return Directory.CreateDirectory(path) != null; } /// diff --git a/source/VersionHandlerImpl/unit_tests/src/FileUtilsTest.cs b/source/VersionHandlerImpl/unit_tests/src/FileUtilsTest.cs index dd7d7c7c..3aaa62f6 100644 --- a/source/VersionHandlerImpl/unit_tests/src/FileUtilsTest.cs +++ b/source/VersionHandlerImpl/unit_tests/src/FileUtilsTest.cs @@ -391,5 +391,50 @@ public void ReplaceBaseAssetsOrPackagesFolder() { "Foo/Bar", "Assets"), Is.EqualTo("Foo/Bar")); } + + /// + /// Test FileUtils.IsValidGuid() when it returns true + /// + [Test] + public void IsValidGuid_TrueCases() { + Assert.That( + FileUtils.IsValidGuid("4b7c4a82-79ca-4eb5-a154-5d78a3b3d3d7"), + Is.EqualTo(true)); + + Assert.That( + FileUtils.IsValidGuid("017885d9f22374a53844077ede0ccda6"), + Is.EqualTo(true)); + } + + /// + /// Test FileUtils.IsValidGuid() when it returns false + /// + [Test] + public void IsValidGuid_FalseCases() { + Assert.That( + FileUtils.IsValidGuid(""), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid(null), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid("00000000-0000-0000-0000-000000000000"), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid("00000000000000000000000000000000"), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid("g000000000000000000000000000000"), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid(" "), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid("12300000 0000 0000 0000 000000000000"), + Is.EqualTo(false)); + Assert.That( + FileUtils.IsValidGuid("12300000\n0000\n0000\n0000\n000000000000"), + Is.EqualTo(false)); + } } }