Exemple #1
0
        private static string ResolveNpmVersion(string nodeVersion)
        {
            string programFiles         = SystemEnvironment.GetFolderPath(SystemEnvironment.SpecialFolder.ProgramFilesX86);
            string appSettingNpmVersion = SystemEnvironment.GetEnvironmentVariable("WEBSITE_NPM_DEFAULT_VERSION");

            if (!string.IsNullOrEmpty(appSettingNpmVersion))
            {
                return(appSettingNpmVersion);
            }
            else if (nodeVersion.Equals("4.1.2", StringComparison.OrdinalIgnoreCase))
            {
                // This case is only to work around node version 4.1.2 with npm 2.x failing to publish ASP.NET 5 apps due to long path issues.
                return("3.3.6");
            }
            else
            {
                string npmTxtPath = Path.Combine(programFiles, "nodejs", nodeVersion, "npm.txt");

                return(FileSystemHelpers.FileExists(npmTxtPath) ? FileSystemHelpers.ReadAllTextFromFile(npmTxtPath).Trim() : DefaultNpmVersion);
            }
        }
Exemple #2
0
        private static bool TryGetAspNet5Sdk(string rootPath, IFileFinder fileFinder, out AspNet5Sdk aspNetSdk)
        {
            aspNetSdk = null;
            var globalJsonFiles = fileFinder.ListFiles(rootPath, SearchOption.AllDirectories, new[] { "*global.json" })
                                  .Where(path => Path.GetFileName(path).Equals("global.json", StringComparison.OrdinalIgnoreCase))
                                  .ToList();

            if (globalJsonFiles.Count == 1 && FileSystemHelpers.FileExists(globalJsonFiles.First()))
            {
                var parsedGlobalJson = JObject.Parse(FileSystemHelpers.ReadAllText(globalJsonFiles.First()));
                if (parsedGlobalJson["sdk"] != null)
                {
                    aspNetSdk = parsedGlobalJson["sdk"].ToObject <AspNet5Sdk>();
                    if (string.IsNullOrEmpty(aspNetSdk.Architecture))
                    {
                        aspNetSdk.Architecture = GetDefaultAspNet5RuntimeArchitecture();
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        protected override void OnLockRelease()
        {
            base.OnLockRelease();

            if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground && shutdownDelayed)
            {
                ShutdownDelaySemaphore.GetInstance().Release(_traceFactory.GetTracer());
            }
            else
            {
                OperationManager.SafeExecute(() => {
                    // Delete the Sentinel file to signal DWAS that deployment is complete
                    if (!String.IsNullOrEmpty(siteRoot))
                    {
                        string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                        if (FileSystemHelpers.FileExists(sentinelPath))
                        {
                            FileSystemHelpers.DeleteFile(sentinelPath);
                        }
                    }
                });
            }
        }
Exemple #4
0
 private static bool IsNodeVersionInstalled(string version)
 {
     string programFiles = SystemEnvironment.GetFolderPath(SystemEnvironment.SpecialFolder.ProgramFilesX86);
     return (!String.IsNullOrEmpty(version)) &&
            FileSystemHelpers.FileExists(Path.Combine(programFiles, "nodejs", version, "node.exe"));
 }
Exemple #5
0
 public static void MoveFile(string sourceFileName, string destFileName)
 {
     FileSystemHelpers.DeleteFileSafe(destFileName);
     Instance.File.Move(sourceFileName, destFileName);
 }
Exemple #6
0
        private void EnsureProperties()
        {
            if (_initialized)
            {
                return;
            }

            _projectName = _projectNameProperty.GetValue <string>(_projectInstance);
            var projectType  = _projectTypeProperty.GetValue <SolutionProjectType>(_projectInstance);
            var relativePath = _relativePathProperty.GetValue <string>(_projectInstance);

            _isWebSite = projectType == SolutionProjectType.WebProject;

            // When using websites with IISExpress, the relative path property becomes a URL.
            // When that happens we're going to grab the path from the Release.AspNetCompiler.PhysicalPath
            // property in the solution.

            Uri uri;

            if (_isWebSite && Uri.TryCreate(relativePath, UriKind.Absolute, out uri))
            {
                var aspNetConfigurations = _aspNetConfigurationsProperty.GetValue <Hashtable>(_projectInstance);

                // Use the release configuraiton and debug if it isn't available
                object configurationObject = aspNetConfigurations["Release"] ?? aspNetConfigurations["Debug"];

                // REVIEW: Is there always a configuration object (i.e. can this ever be null?)

                // The aspNetPhysicalPath contains the relative to the website
                FieldInfo aspNetPhysicalPathField = configurationObject.GetType().GetField("aspNetPhysicalPath", BindingFlags.NonPublic | BindingFlags.Instance);

                relativePath = (string)aspNetPhysicalPathField.GetValue(configurationObject);
            }

            _absolutePath = Path.Combine(Path.GetDirectoryName(_solutionPath), relativePath);
            if (FileSystemHelpers.FileExists(_absolutePath))
            {
                // used to determine project type
                _projectTypeGuids = VsHelper.GetProjectTypeGuids(_absolutePath);
                if (AspNetCoreHelper.IsDotnetCoreFromProjectFile(_absolutePath, _projectTypeGuids))
                {
                    _isAspNetCore = true;
                }
                else if (projectType == SolutionProjectType.KnownToBeMSBuildFormat)
                {
                    // KnownToBeMSBuildFormat: C#, VB, and VJ# projects
                    // Check if it's a wap
                    _isWap = VsHelper.IsWap(_projectTypeGuids);

                    _isExecutable = VsHelper.IsExecutableProject(_absolutePath);
                }
                else if (FunctionAppHelper.LooksLikeFunctionApp())
                {
                    _isFunctionApp = true;
                }
            }
            else
            {
                _projectTypeGuids = Enumerable.Empty <Guid>();
            }

            _initialized = true;
        }
        public static void Extract(this ZipArchive archive, string directoryName)
        {
            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                string path = Path.Combine(directoryName, entry.FullName);
                if (entry.Length == 0 && (path.EndsWith("/", StringComparison.Ordinal) || path.EndsWith("\\", StringComparison.Ordinal)))
                {
                    // Extract directory
                    FileSystemHelpers.CreateDirectory(path);
                }
                else
                {
                    FileInfoBase fileInfo = FileSystemHelpers.FileInfoFromFileName(path);

                    if (!fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }

                    using (Stream zipStream = entry.Open(),
                           fileStream = fileInfo.Open(FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                    {
                        zipStream.CopyTo(fileStream);
                    }

                    bool   createSymLink    = false;
                    string originalFileName = string.Empty;
                    if (!OSDetector.IsOnWindows())
                    {
                        try
                        {
                            using (Stream fs = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                byte[] buffer = new byte[10];
                                fs.Read(buffer, 0, buffer.Length);
                                fs.Close();

                                var str = System.Text.Encoding.Default.GetString(buffer);
                                if (str.StartsWith("../"))
                                {
                                    string fullPath = Path.GetFullPath(str);
                                    if (fullPath.StartsWith(directoryName))
                                    {
                                        createSymLink    = true;
                                        originalFileName = fullPath;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Could not identify symlinks in zip file : " + ex.ToString());
                        }
                    }

                    fileInfo.LastWriteTimeUtc = entry.LastWriteTime.ToUniversalTime().DateTime;

                    if (createSymLink)
                    {
                        try
                        {
                            fileInfo.Delete();

                            Mono.Unix.UnixFileInfo unixFileInfo = new Mono.Unix.UnixFileInfo(originalFileName);
                            unixFileInfo.CreateSymbolicLink(path);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Could not create symlinks : " + ex.ToString());
                        }
                    }
                }
            }
        }
Exemple #8
0
        public bool Lock(string operationName)
        {
            Stream lockStream = null;
            var    ignoreCloseStreamException = false;

            try
            {
                FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(_path));

                lockStream = FileSystemHelpers.OpenFile(_path, FileMode.Create, FileAccess.Write, FileShare.Read);

                WriteLockInfo(operationName, lockStream);

                OnLockAcquired();

                _lockStream = lockStream;
                lockStream  = null;

                if (_traceLock)
                {
                    _traceFactory.GetTracer().Trace($"LockFile '{_path}' acquired");
                }

                return(true);
            }
            catch (UnauthorizedAccessException)
            {
                if (!_ensureLock)
                {
                    // if it is ReadOnly file system, we will skip the lock
                    // which will enable all read action
                    // for write action, it will fail with UnauthorizedAccessException when perform actual write operation
                    //      There is one drawback, previously for write action, even acquire lock will fail with UnauthorizedAccessException,
                    //      there will be retry within given timeout. so if exception is temporary, previous`s implementation will still go thru.
                    //      While right now will end up failure. But it is a extreme edge case, should be ok to ignore.
                    ignoreCloseStreamException = FileSystemHelpers.IsFileSystemReadOnly();
                    return(ignoreCloseStreamException);
                }
            }
            catch (IOException ex)
            {
                if (!_ensureLock)
                {
                    // if not enough disk space, no one has the lock.
                    // let the operation thru and fail where it would try to get the file
                    ignoreCloseStreamException = ex.Message.Contains(NotEnoughSpaceText);
                    return(ignoreCloseStreamException);
                }
            }
            catch (Exception ex)
            {
                TraceIfUnknown(ex);
            }
            finally
            {
                if (lockStream != null)
                {
                    OperationManager.CriticalExecute("LockFile.Lock.Finally", () => lockStream.Close(), _ => !ignoreCloseStreamException);
                }
            }

            return(false);
        }