Пример #1
0
 public void TestNormalizePath()
 {
     Assert.Equal("", FsEntry.NormalizePath("."));
     Assert.Equal("", FsEntry.NormalizePath("././././././////"));
     Assert.Equal("abc", FsEntry.NormalizePath("abc"));
     Assert.Equal("abc", FsEntry.NormalizePath(".\\abc"));
     Assert.Equal("..", FsEntry.NormalizePath(".."));
 }
Пример #2
0
        public void WriteFsEntry(FsEntry fsEntry)
        {
            WriteString(fsEntry.Path);
            if (fsEntry.IsEmpty)
            {
                return;
            }

            WriteLong(fsEntry.Length);
            WriteDateTime(fsEntry.LastWriteTime);
        }
Пример #3
0
        public static SyncPath Parse(string path)
        {
            SyncPath syncPath;

            // replace \ to /
            path = FsEntry.NormalizePath(path);

            // [UserName@]Host:Path (host 2+ symbols)
            var userHostPathRegex = new Regex("^([^@:/]+@)?([^:/]{2,}:)?(/.*)$");
            var userHostPathMatch = userHostPathRegex.Match(path);

            if (userHostPathMatch.Success)
            {
                syncPath = new SyncPath
                {
                    UserName = userHostPathMatch.Groups[1].Value.TrimEnd('@'),
                    Host     = userHostPathMatch.Groups[2].Value.TrimEnd(':'),
                    Path     = userHostPathMatch.Groups[3].Value
                };
            }
            else
            {
                // [drive:]/path (drive 1 symbol)
                var windowsPathRegex = new Regex("^([^:/]:)?(/.*)$");
                var windowsPathMatch = windowsPathRegex.Match(path);
                if (windowsPathMatch.Success)
                {
                    syncPath = new SyncPath
                    {
                        UserName = "",
                        Host     = "",
                        Path     = windowsPathMatch.Value
                    };
                }
                else
                {
                    return(null);
                }
            }


            if (!string.IsNullOrEmpty(syncPath.Host) && string.IsNullOrEmpty(syncPath.UserName))
            {
                syncPath.UserName = Environment.UserName;
            }

            return(syncPath);
        }
Пример #4
0
 private string GetPath(string fullPath)
 {
     return(FsEntry.NormalizePath(Path.GetRelativePath(_srcPath, fullPath)));
 }