Example #1
0
 /// <summary>
 /// CoreCLR doesn't honour umask value for the new file/folder created. As a workaround change the permission using chmod after file is created.
 /// Setting default permission to 0644, i.e. read/write for Owner & Read only for group & others.
 /// </summary>
 internal static void UpdateFilePermission(string filePath, int filePermission = LINUX_DEFAULT_PERMISSION)
 {
     if (FabricFile.Exists(filePath) || FabricDirectory.Exists(filePath))
     {
         NativeHelper.chmod(filePath, filePermission);
     }
 }
Example #2
0
        /// <summary>
        /// Creates the given directory if it doesn't exist on the given machine
        /// If the machineName is null, the local machine is assumed to be the default
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="machineName"></param>
        internal static void CreateDirectoryIfNotExist(string directory, string machineName)
        {
#if DotNetCoreClrLinux
            if (string.IsNullOrEmpty(machineName) && !FabricDirectory.Exists(directory))
            {
                FabricDirectory.CreateDirectory(directory);
            }
            else if (!string.IsNullOrEmpty(machineName))
            {
                string remotePath = GetRemotePath(directory, machineName);
                if (!FabricDirectory.Exists(remotePath))
                {
                    FabricDirectory.CreateDirectory(remotePath);
                }
            }
#else
            if (string.IsNullOrEmpty(machineName) && !Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            else if (!string.IsNullOrEmpty(machineName))
            {
                string remotePath = GetRemotePath(directory, machineName);
                if (!Directory.Exists(remotePath))
                {
                    Directory.CreateDirectory(remotePath);
                }
            }
#endif
        }
Example #3
0
        /// <summary>
        /// Removes the given directory if it exists on the given machine
        /// If the machineName is null, the local machine is assumed to be the default
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="machineName"></param>
        internal static void DeleteDirectoryIfExist(string directory, string machineName)
        {
#if DotNetCoreClrLinux
            if (!string.IsNullOrEmpty(machineName))
            {
                directory = GetRemotePath(directory, machineName);
            }

            if (FabricDirectory.Exists(directory))
            {
                string[] files = FabricDirectory.GetFiles(directory);
                string[] dirs  = FabricDirectory.GetDirectories(directory);

                foreach (string file in files)
                {
                    File.SetAttributes(file, FileAttributes.Normal);
                    File.Delete(file);
                }

                FabricDirectory.Delete(directory, true);
            }
#else
            if (!string.IsNullOrEmpty(machineName))
            {
                directory = GetRemotePath(directory, machineName);
            }

            if (Directory.Exists(directory))
            {
                Directory.Delete(directory, true);
            }
#endif
        }
Example #4
0
        internal static string GetNewTempPath()
        {
            string tempPath;

            do
            {
                tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            } while (FabricFile.Exists(tempPath) || FabricDirectory.Exists(tempPath));
            return(tempPath);
        }
        public static string GetCabVersion(string cabPath)
        {
            string tempPath      = Helpers.GetNewTempPath();
            string fileToExtract = Path.Combine(Constants.PathToFabricCode, Constants.FabricExe);
            string tempFile      = Path.Combine(tempPath, fileToExtract);

            ExtractFiltered(cabPath, tempPath, new string[] { fileToExtract }, true);
            if (!File.Exists(tempFile)) // Package is WU
            {
                fileToExtract = Constants.FabricExe;
                tempFile      = Path.Combine(tempPath, fileToExtract);
                ExtractFiltered(cabPath, tempPath, new string[] { fileToExtract }, true);
                if (!File.Exists(tempFile))
                {
                    throw new FileNotFoundException(string.Format("{0} was not extracted from CAB package.", Constants.FabricExe));
                }
            }

            try
            {
                var fileVersion = FileVersionInfo.GetVersionInfo(tempFile);
                return(string.Format(
                           CultureInfo.InvariantCulture,
                           "{0}.{1}.{2}.{3}",
                           fileVersion.FileMajorPart,
                           fileVersion.FileMinorPart,
                           fileVersion.FileBuildPart,
                           fileVersion.FilePrivatePart));
            }
            finally
            {
                if (Directory.Exists(tempPath))
                {
                    try
                    {
                        FabricDirectory.Delete(tempPath, true, true);
                    }
                    catch { }
                }
            }
        }