internal void RemoveAllCodegenFiles() { this.RemoveCodegenResourceDir(); foreach (FileData data in (IEnumerable)FileEnumerator.Create(base._cacheDir)) { if (data.IsDirectory) { if (((data.Name != "assembly") && (data.Name != "hash")) && !StringUtil.StringStartsWith(data.Name, "Sources_")) { try { this.DeleteFilesInDirectory(data.FullName); } catch { } } } else { DiskBuildResultCache.TryDeleteFile(data.FullName); } } AppDomainSetup setupInformation = Thread.GetDomain().SetupInformation; UnsafeNativeMethods.DeleteShadowCache(setupInformation.CachePath, setupInformation.ApplicationName); }
internal void RemoveAllCodegenFiles() { Debug.Trace("BuildResultCache", "Deleting all files from " + _cacheDir); RemoveCodegenResourceDir(); // Remove everything in the codegen directory, as well as all the subdirectories // used for culture assemblies // Go through all the files in the codegen dir. Delete everything, except // for the fusion cache, which is in the "assembly" subdirectory foreach (FileData fileData in FileEnumerator.Create(_cacheDir)) { // If it's a directories if (fileData.IsDirectory) { // Skip the fusion cache if (fileData.Name == fusionCacheDirectoryName) { continue; } // Skip the "hash" folder if (fileData.Name == webHashDirectoryName) { continue; } // Skip the source files generated for the designer (VSWhidbey 138194) if (StringUtil.StringStartsWith(fileData.Name, CodeDirectoryCompiler.sourcesDirectoryPrefix)) { continue; } try { // If it is a directory, only remove the files inside and not the directory itself // VSWhidbey 596757 DeleteFilesInDirectory(fileData.FullName); } catch { } // Ignore all exceptions continue; } // VSWhidbey 564168 Do not delete files that cannot be deleted, these files are still // referenced by other appdomains that are in the process of shutting down. // We also do not rename as renaming can cause an assembly not to be found if another // appdomain tries to compile against it. DiskBuildResultCache.TryDeleteFile(fileData.FullName); } // Clean up the fusion shadow copy cache AppDomainSetup appDomainSetup = Thread.GetDomain().SetupInformation; UnsafeNativeMethods.DeleteShadowCache(appDomainSetup.CachePath, appDomainSetup.ApplicationName); }
// Deletes all files in the directory, but leaves the directory there internal void DeleteFilesInDirectory(string path) { foreach (FileData fileData in FileEnumerator.Create(path)) { if (fileData.IsDirectory) { Directory.Delete(fileData.FullName, true /*recursive*/); continue; } Util.RemoveOrRenameFile(fileData.FullName); } }
internal MapPathBasedVirtualPathEnumerator(VirtualPath virtualPath, RequestedEntryType requestedEntryType) { string str; if (virtualPath.IsRelative) { throw new ArgumentException(System.Web.SR.GetString("Invalid_app_VirtualPath"), "virtualPath"); } this._virtualPath = virtualPath; this._requestedEntryType = requestedEntryType; if (!ServerConfig.UseServerConfig) { str = this._virtualPath.MapPathInternal(); } else { IServerConfig instance = ServerConfig.GetInstance(); this._serverConfig2 = instance as IServerConfig2; str = instance.MapPath(null, this._virtualPath); if (this._requestedEntryType != RequestedEntryType.Files) { if (this._serverConfig2 == null) { string[] strArray = instance.GetVirtualSubdirs(this._virtualPath, false); if (strArray != null) { this._exclude = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string str2 in strArray) { this._exclude[str2] = str2; } } } string[] virtualSubdirs = instance.GetVirtualSubdirs(this._virtualPath, true); if (virtualSubdirs != null) { this._virtualPaths = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string str3 in virtualSubdirs) { VirtualPath path = this._virtualPath.SimpleCombineWithDir(str3); if (FileUtil.DirectoryExists(instance.MapPath(null, path))) { this._virtualPaths[str3] = new MapPathBasedVirtualDirectory(path.VirtualPathString); } } this._virtualEnumerator = this._virtualPaths.Values.GetEnumerator(); } } } this._fileEnumerator = FileEnumerator.Create(str); this._useFileEnumerator = false; }
internal void DeleteFilesInDirectory(string path) { foreach (FileData data in (IEnumerable)FileEnumerator.Create(path)) { if (data.IsDirectory) { Directory.Delete(data.FullName, true); } else { Util.RemoveOrRenameFile(data.FullName); } } }
internal void RemoveOldTempFiles() { this.RemoveCodegenResourceDir(); string path = base._cacheDir + @"\"; foreach (FileData data in (IEnumerable)FileEnumerator.Create(path)) { if (!data.IsDirectory) { string extension = Path.GetExtension(data.Name); switch (extension) { case ".dll": case ".pdb": case ".web": case ".ccu": case ".compiled": { continue; } } if (extension != ".delete") { int length = data.Name.LastIndexOf('.'); if (length <= 0) { goto Label_013A; } string str3 = data.Name.Substring(0, length); int index = str3.IndexOf('.'); int num3 = str3.LastIndexOf('.'); if ((num3 > 0) && (index != num3)) { str3 = str3.Substring(0, num3); } if (!FileUtil.FileExists(path + str3 + ".dll") && !FileUtil.FileExists(path + "App_Web_" + str3 + ".dll")) { goto Label_013A; } } else { DiskBuildResultCache.CheckAndRemoveDotDeleteFile(new FileInfo(data.FullName)); } } continue; Label_013A: Util.DeleteFileNoException(data.FullName); } }
internal CbmCodeGeneratorBuildProviderHost(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string generatedFilesDir, string outputAssemblyName) : base(compConfig, referencedAssemblies, compilerType, outputAssemblyName) { if (Directory.Exists(generatedFilesDir)) { foreach (FileData data in (IEnumerable)FileEnumerator.Create(generatedFilesDir)) { if (!data.IsDirectory) { File.Delete(data.FullName); } } } Directory.CreateDirectory(generatedFilesDir); this._generatedFilesDir = generatedFilesDir; }
internal MapPathBasedVirtualPathEnumerator(VirtualPath virtualPath, RequestedEntryType requestedEntryType) { if (virtualPath.IsRelative) { throw new ArgumentException(SR.GetString(SR.Invalid_app_VirtualPath), "virtualPath"); } _virtualPath = virtualPath; _requestedEntryType = requestedEntryType; string physicalPath; if (!ServerConfig.UseServerConfig) { // Use the hosting environment to map the virtual path physicalPath = _virtualPath.MapPathInternal(); } else { IServerConfig serverConfig = ServerConfig.GetInstance(); _serverConfig2 = serverConfig as IServerConfig2; // Use serverConfig to map the virtual path physicalPath = serverConfig.MapPath(null, _virtualPath); if (_requestedEntryType != RequestedEntryType.Files) { // For MetabaseServerConfig, get the subdirs that are not in the application, and add them to the exclude list. if (_serverConfig2 == null) { string [] virtualSubdirsNotInApp = serverConfig.GetVirtualSubdirs(_virtualPath, false); if (virtualSubdirsNotInApp != null) { _exclude = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string subdir in virtualSubdirsNotInApp) { _exclude[subdir] = subdir; } } } // Get subdirs that are virtual directories, and record their physical mappings. // Ignore the virtualPaths if we only need files, since it only contains directories string [] virtualSubdirsInApp = serverConfig.GetVirtualSubdirs(_virtualPath, true); if (virtualSubdirsInApp != null) { _virtualPaths = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string subdir in virtualSubdirsInApp) { VirtualPath subpath = _virtualPath.SimpleCombineWithDir(subdir); string subPhysicalPath = serverConfig.MapPath(null, subpath); if (FileUtil.DirectoryExists(subPhysicalPath)) { _virtualPaths[subdir] = new MapPathBasedVirtualDirectory(subpath.VirtualPathString); } } // Create enumerator for the virtual paths _virtualEnumerator = _virtualPaths.Values.GetEnumerator(); } } } // Create an enumerator for the physical files and directories at this path _fileEnumerator = FileEnumerator.Create(physicalPath); // Reset the enumerator. Note that we don't support the Reset method. _useFileEnumerator = false; }
/* * Delete all temporary files from the codegen directory (e.g. source files, ...) */ internal void RemoveOldTempFiles() { Debug.Trace("BuildResultCache", "Deleting old temporary files from " + _cacheDir); RemoveCodegenResourceDir(); string codegen = _cacheDir + "\\"; // Go through all the files in the codegen dir foreach (FileData fileData in FileEnumerator.Create(codegen)) { // Skip directories if (fileData.IsDirectory) { continue; } // If it has a known extension, skip it string ext = Path.GetExtension(fileData.Name); if (ext == ".dll" || ext == ".pdb" || ext == ".web" || ext == ".ccu" || ext == ".prof" || ext == preservationFileExtension) { continue; } // .delete files need to be removed. if (ext != dotDelete) { // Don't delete the temp file if it's named after a dll that's still around // since it could still be useful for debugging. // Note that we can't use GetFileNameWithoutExtension here because // some of the files are named 5hvoxl6v.0.cs, and it would return // 5hvoxl6v.0 instead of just 5hvoxl6v int periodIndex = fileData.Name.LastIndexOf('.'); if (periodIndex > 0) { string baseName = fileData.Name.Substring(0, periodIndex); int secondPeriodIndex = baseName.LastIndexOf('.'); if (secondPeriodIndex > 0) { baseName = baseName.Substring(0, secondPeriodIndex); } // Generated source files uses assemblyname as prefix so we should keep them. if (FileUtil.FileExists(codegen + baseName + ".dll")) { continue; } // other generated files, such as .cmdline, .err and .out need to add the // WebAssemblyNamePrefix, since they do not use the assembly name as prefix. if (FileUtil.FileExists(codegen + BuildManager.WebAssemblyNamePrefix + baseName + ".dll")) { continue; } } } else { // Additional logic for VSWhidbey 564168 / Visual Studio QFE 4710. // Delete both original .dll and .delete if possible DiskBuildResultCache.CheckAndRemoveDotDeleteFile(new FileInfo(fileData.FullName)); continue; } Debug.Trace("BuildResultCache", "Deleting old temporary files: " + fileData.FullName); try { File.Delete(fileData.FullName); } catch { } } }