Ejemplo n.º 1
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
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 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
        }
Ejemplo n.º 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);
        }