internal void ReadExistingContainerSigningCache() { _log.LogMessage("Loading existing files from cache"); foreach (var file in Directory.EnumerateFiles(_pathToContainerUnpackingDirectory, "*.*", SearchOption.AllDirectories)) { string cacheRelative = file.Replace(_pathToContainerUnpackingDirectory + Path.DirectorySeparatorChar, ""); int indexOfHash = cacheRelative.IndexOf(Path.DirectorySeparatorChar); if (indexOfHash <= 0) { continue; } // When reading from an existing cache use the already computed hash from the directory // structure instead of computing it from the file because things like signing // might have changed the hash but we want to still use the same hash of the unsigned // file that originally built the cache. string stringHash = cacheRelative.Substring(0, indexOfHash); try { ImmutableArray <byte> contentHash = ContentUtil.StringToHash(stringHash); } catch { _log.LogMessage($"Failed to parse the content hash from path '{file}' so skipping it."); continue; } TrackFile(file, ContentUtil.StringToHash(stringHash), false); } _log.LogMessage("Done loading existing files from cache"); }
internal void ReadExistingContainerSigningCache() { _log.LogMessage("Loading existing files from cache"); foreach (var file in Directory.EnumerateFiles(_pathToContainerUnpackingDirectory, "*.*", SearchOption.AllDirectories)) { string cacheRelative = file.Replace(_pathToContainerUnpackingDirectory + Path.DirectorySeparatorChar, ""); int indexOfHash = cacheRelative.IndexOf(Path.DirectorySeparatorChar); if (indexOfHash <= 0) { continue; } // When reading from an existing cache use the already computed hash from the directory // structure instead of computing it from the file because things like signing // might have changed the hash but we want to still use the same hash of the unsigned // file that originally built the cache. string stringHash = cacheRelative.Substring(0, indexOfHash); ImmutableArray <byte> contentHash; try { contentHash = ContentUtil.StringToHash(stringHash); } catch { _log.LogMessage($"Failed to parse the content hash from path '{file}' so skipping it."); continue; } // if the content of the file doesn't match the hash in file path than the file has changed // which indicates that it was signed so we need to ensure we repack the binary with the signed version string actualFileHash = ContentUtil.HashToString(ContentUtil.GetContentHash(file)); bool forceRepack = stringHash != actualFileHash; _hashToCollisionIdMap.TryGetValue(new SignedFileContentKey(contentHash, Path.GetFileName(file)), out string collisionPriorityId); TrackFile(file, collisionPriorityId, contentHash, false, forceRepack, containerPath: file); } _log.LogMessage("Done loading existing files from cache"); }