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);
        }
 private void AddBuildProviders(bool retryIfDeletionHappens)
 {
     DiskBuildResultCache.ResetAssemblyDeleted();
     foreach (VirtualFile file in this._vdir.Files)
     {
         BuildResult vPathBuildResultFromCache = null;
         try
         {
             vPathBuildResultFromCache = BuildManager.GetVPathBuildResultFromCache(file.VirtualPathObject);
         }
         catch
         {
             if (!BuildManager.PerformingPrecompilation)
             {
                 continue;
             }
         }
         if (vPathBuildResultFromCache == null)
         {
             System.Web.Compilation.BuildProvider provider = BuildManager.CreateBuildProvider(file.VirtualPathObject, this._compConfig, this._referencedAssemblies, false);
             if (provider != null)
             {
                 this._buildProviders[file.VirtualPath] = provider;
             }
         }
     }
     if ((DiskBuildResultCache.InUseAssemblyWasDeleted && retryIfDeletionHappens) && BuildManager.PerformingPrecompilation)
     {
         this.AddBuildProviders(false);
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
        private static bool AssemblyIsInvalid(Assembly a)
        {
            string assemblyCodeBase = Util.GetAssemblyCodeBase(a);

            if (FileUtil.FileExists(assemblyCodeBase))
            {
                return(DiskBuildResultCache.HasDotDeleteFile(assemblyCodeBase));
            }
            return(true);
        }
Exemple #5
0
        private static void RemoveAssembly(string path)
        {
            FileInfo f = new FileInfo(path);

            DiskBuildResultCache.RemoveAssembly(f);
            string str = Path.ChangeExtension(f.FullName, ".pdb");

            if (File.Exists(str))
            {
                DiskBuildResultCache.TryDeleteFile(new FileInfo(str));
            }
        }
        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);
            }
        }
Exemple #7
0
        private static void RemoveAssembly(string path)
        {
            var f = new FileInfo(path);

            DiskBuildResultCache.RemoveAssembly(f);
            // Delete the associated pdb file as well, since it is possible to
            // run into a situation where the dependency has changed just
            // when the cache item is about to get inserted, resulting in
            // the callback deleting only the dll file and leaving behind the
            // pdb file. (Dev10 bug 846606)
            var pdbPath = Path.ChangeExtension(f.FullName, ".pdb");

            if (File.Exists(pdbPath))
            {
                DiskBuildResultCache.TryDeleteFile(new FileInfo(pdbPath));
            }
        }
 private void InvalidateInvalidAssembly(CompilerResults results, CompilerParameters compilParams)
 {
     if ((results != null) && results.Errors.HasErrors)
     {
         foreach (CompilerError error in results.Errors)
         {
             if (!error.IsWarning && System.Web.Util.StringUtil.EqualsIgnoreCase(error.ErrorNumber, "CS0016"))
             {
                 if (this.CultureName != null)
                 {
                     DiskBuildResultCache.TryDeleteFile(new FileInfo(Path.Combine(this._tempFiles.TempDir, this.OutputAssemblyName + ".dll")));
                 }
                 DiskBuildResultCache.TryDeleteFile(compilParams.OutputAssembly);
             }
         }
     }
 }
Exemple #9
0
        private void RemoveAssemblyAndCleanupDependencies(string assemblyName)
        {
            bool gotLock = false;

            try
            {
                CompilationLock.GetLock(ref gotLock);
                lock (this._dependentAssemblies)
                {
                    this.RemoveAssemblyAndCleanupDependenciesNoLock(assemblyName);
                }
            }
            finally
            {
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
Exemple #10
0
        private void RemoveAssemblyAndCleanupDependencies(string assemblyName)
        {
            bool gotLock = false;

            try {
                // Grab the compilation mutex, since we will remove cached build result
                CompilationLock.GetLock(ref gotLock);

                // Protect the dependent assemblies table, as it's accessed/modified in the recursion
                lock (_dependentAssemblies) {
                    RemoveAssemblyAndCleanupDependenciesNoLock(assemblyName);
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
 internal PreservationFileReader(DiskBuildResultCache diskCache, bool precompilationMode) {
     _diskCache = diskCache;
     _precompilationMode = precompilationMode;
 }
Exemple #12
0
        /*
         * 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 { }
            }
        }
Exemple #13
0
        /*
         * Delete an assembly and all its related files.  The assembly is typically named
         * something like ASPNET.jnw_y10n.dll, while related files are simply jnw_y10n.*.
         */
        internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName)
        {
            Debug.Trace("DiskBuildResultCache", "RemoveAssemblyAndRelatedFiles(" + assemblyName + ")");

            // If the name doesn't start with the prefix, the cleanup code doesn't apply
            if (!assemblyName.StartsWith(BuildManager.WebAssemblyNamePrefix, StringComparison.Ordinal))
            {
                return;
            }

            // Get rid of the prefix, since related files don't have it
            string baseName = assemblyName.Substring(BuildManager.WebAssemblyNamePrefix.Length);

            bool gotLock = false;

            try {
                // Grab the compilation mutex, since we will remove generated assembly
                CompilationLock.GetLock(ref gotLock);

                DirectoryInfo directory = new DirectoryInfo(_cacheDir);

                // Find all the files that contain the base name
                FileInfo[] files = directory.GetFiles("*" + baseName + ".*");
                foreach (FileInfo f in files)
                {
                    if (f.Extension == ".dll")
                    {
                        // Notify existing buildresults that result assembly will be removed.
                        // This is required otherwise new components can be compiled
                        // with obsolete build results whose assembly has been removed.
                        string assemblyKey = GetAssemblyCacheKey(f.FullName);
                        HttpRuntime.CacheInternal.Remove(assemblyKey);

                        // Remove the assembly
                        RemoveAssembly(f);

                        // Also, remove satellite assemblies that may be associated with it
                        StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName);
                    }
                    else if (f.Extension == dotDelete)
                    {
                        CheckAndRemoveDotDeleteFile(f);
                    }
                    else
                    {
                        // Remove the file, or if not possible, rename it, so it'll get
                        // cleaned up next time by RemoveOldTempFiles()

                        TryDeleteFile(f);
                    }
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
 internal PreservationFileReader(DiskBuildResultCache diskCache, bool precompilationMode)
 {
     this._diskCache          = diskCache;
     this._precompilationMode = precompilationMode;
 }
Exemple #15
0
        private void AddBuildProviders(bool retryIfDeletionHappens)
        {
            DiskBuildResultCache.ResetAssemblyDeleted();

            foreach (VirtualFile vfile in _vdir.Files)
            {
                // If it's already built and up to date, skip it
                BuildResult result = null;
                try {
                    result = BuildManager.GetVPathBuildResultFromCache(vfile.VirtualPathObject);
                }
                catch {
                    // Ignore the cached error in batch compilation mode, since we want to compile
                    // as many files as possible.
                    // But don't ignore it in CBM or precompile cases, since we always want to try
                    // to compile everything that had failed before.
                    if (!BuildManager.PerformingPrecompilation)
                    {
                        // Skip it if an exception occurs (e.g. if a compile error was cached for it)
                        continue;
                    }
                }

                if (result != null)
                {
                    continue;
                }

                BuildProvider buildProvider = BuildManager.CreateBuildProvider(vfile.VirtualPathObject,
                                                                               _compConfig, _referencedAssemblies, false /*failIfUnknown*/);

                // Non-supported file type
                if (buildProvider == null)
                {
                    continue;
                }

                // IgnoreFileBuildProvider's should never be created
                Debug.Assert(!(buildProvider is IgnoreFileBuildProvider));

                _buildProviders[vfile.VirtualPath] = buildProvider;
            }

            // If an assembly had to be deleted/renamed as a result of calling GetVPathBuildResultFromCache,
            // me way need to run the AddBuildProviders logic again.  The reason is that as a result of
            // deleting the assembly, we may have invalidated other BuildResult that we had earlier found
            // to be up to date (VSWhidbey 269297)
            if (DiskBuildResultCache.InUseAssemblyWasDeleted)
            {
                Debug.Assert(retryIfDeletionHappens);

                // Only retry if we're doing precompilation.  For standard batching, we can live
                // with the fact that not everything will be built after we're done (and we want to
                // be done as quickly as possible since the user is waiting).
                if (retryIfDeletionHappens && BuildManager.PerformingPrecompilation)
                {
                    Debug.Trace("WebDirectoryBatchCompiler", "Rerunning AddBuildProviders for '" +
                                _vdir.VirtualPath + "' because an assembly was out of date.");

                    // Pass false for retryIfDeletionHappens to make sure we don't get in an
                    // infinite recursion.
                    AddBuildProviders(false /*retryIfDeletionHappens*/);
                }
            }
        }