示例#1
0
 /// <summary>
 /// Serialize the symlink definitions for load using <see cref="Deserialize"/>
 /// </summary>
 /// <param name="writer">the writer</param>
 /// <param name="symlinkDefinitions">the symlink definitions (may be null)</param>
 public static void Serialize(BuildXLWriter writer, SymlinkDefinitions symlinkDefinitions)
 {
     writer.Write(symlinkDefinitions == null);
     symlinkDefinitions?.m_symlinkDefinitionMap.Serialize(
         writer,
         kvp =>
     {
         writer.Write(kvp.Key);
         writer.Write(kvp.Value);
     });
 }
示例#2
0
        /// <summary>
        /// Load symlink definitions serialized using <see cref="PathMapSerializer"/>
        /// </summary>
        public static async Task <Possible <SymlinkDefinitions> > TryLoadAsync(
            LoggingContext loggingContext,
            PathTable pathTable,
            string filePath,
            string symlinksDebugPath,
            ITempDirectoryCleaner tempDirectoryCleaner = null)
        {
            try
            {
                var pathMap = await PathMapSerializer.LoadAsync(filePath, pathTable);

                var definitions = new SymlinkDefinitions(pathTable, pathMap);
                Logger.Log.SymlinkFileTraceMessage(
                    loggingContext,
                    I($"Loaded symlink definitions with {definitions.m_symlinkDefinitionMap.Count} entries and {definitions.m_directorySymlinkContents.Count} directories."));
                if (EngineEnvironmentSettings.DebugSymlinkDefinitions && symlinksDebugPath != null)
                {
                    FileUtilities.DeleteFile(symlinksDebugPath, tempDirectoryCleaner: tempDirectoryCleaner);
                    using (var writer = new StreamWriter(symlinksDebugPath))
                    {
                        foreach (var entry in pathMap)
                        {
                            writer.WriteLine("Source: {0}", entry.Key.ToString(pathTable));
                            writer.WriteLine("Target: {0}", entry.Value.ToString(pathTable));
                        }
                    }
                }

                return(definitions);
            }
            catch (Exception ex)
            {
                Logger.Log.FailedLoadSymlinkFile(loggingContext, ex.GetLogEventMessage());
                return(new Failure <string>("Failed loading symlink definition file"));
            }
        }