void LoadSolutionInfo() { string dir, path, user; _rawSolutionDirectory = null; _solutionDirectory = null; _solutionFile = ""; IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution)); if (sol == null || !VSErr.Succeeded(sol.GetSolutionInfo(out dir, out path, out user))) { return; } if (string.IsNullOrEmpty(dir) || string.IsNullOrEmpty(path)) { // Cache negative result; will be returned as null } else { if (IsSafeSccPath(dir)) { _rawSolutionDirectory = dir; _solutionDirectory = SvnTools.GetTruePath(dir, true) ?? SvnTools.GetNormalizedFullPath(dir); } if (IsSafeSccPath(path)) { _solutionFile = SvnTools.GetTruePath(path, true) ?? SvnTools.GetNormalizedFullPath(path); } } }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) { continue; } string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return(true); }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> toResolve = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsCasingConflicted) { toResolve.Add(item); } } try { foreach (SvnItem item in toResolve) { string svnPath = GetSvnCasing(item); string actualPath = SvnTools.GetTruePath(item.FullPath); if (svnPath == null || actualPath == null) { continue; // not found } if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase)) { continue; // More than casing rename } string svnName = Path.GetFileName(svnPath); string actualName = Path.GetFileName(actualPath); if (svnName == actualName) { continue; // Can't fix directories! } IAnkhOpenDocumentTracker odt = e.GetService <IAnkhOpenDocumentTracker>(); using (odt.LockDocument(svnPath, DocumentLockType.NoReload)) using (odt.LockDocument(actualPath, DocumentLockType.NoReload)) { try { // Try the actual rename File.Move(actualPath, svnPath); } catch { } try { // And try to fix the project+document system VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath); } catch { } } } } finally { e.GetService <IFileStatusMonitor>().ScheduleSvnStatus(SvnItem.GetPaths(toResolve)); } }
public void Path_UncLocalDriveTests() { string sysDir = SvnTools.GetTruePath(System.Environment.GetFolderPath(Environment.SpecialFolder.System)); string testPath = "\\\\" + Environment.MachineName.ToLowerInvariant() + "\\" + sysDir[0] + "$" + sysDir.Substring(2); Assert.That(SvnTools.IsAbsolutePath(testPath)); Assert.That(SvnTools.GetNormalizedFullPath(testPath), Is.EqualTo(testPath), "Fetch normalized"); Assert.That(new SvnPathTarget(testPath).TargetName, Is.EqualTo(testPath), "PathTarget"); Assert.That(SvnTools.GetTruePath(testPath, true), Is.EqualTo(testPath), "Fetch truepath"); }
private string CalculateTruePath(string lpszProjectPath) { string trueName = SvnTools.GetTruePath(lpszProjectPath, true) ?? SvnTools.GetNormalizedFullPath(lpszProjectPath); if (trueName != lpszProjectPath) { if (trueName.Length == lpszProjectPath.Length - 1 && lpszProjectPath[trueName.Length] == '\\') { trueName += '\\'; } } return(trueName); }
public void Path_TestNormalizationTesters() { Assert.That(SvnTools.IsNormalizedFullPath("a:\\"), Is.False, "a:\\ is not normalized"); Assert.That(SvnTools.IsNormalizedFullPath("A:\\"), Is.True, "A:\\ is normalized"); Assert.That(SvnTools.IsNormalizedFullPath("A:\\\\"), Is.False, "A:\\\\ is not normalized"); Assert.That(SvnTools.IsNormalizedFullPath("A:\\.\\"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\..\\"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\...\\"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\..."), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\.svn"), Is.True); Assert.That(SvnTools.IsNormalizedFullPath("A:\\.svn\\"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\\\t.svn"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("A:\\.....svn"), Is.True); Assert.That(SvnTools.GetTruePath("c:\\"), Is.EqualTo("C:\\")); Assert.That(SvnTools.GetTruePath("c:\\" + Guid.NewGuid()), Is.Null); Assert.That(SvnTools.GetTruePath("c:\\-never-exists-", true), Is.Not.Null); Assert.That(SvnTools.IsAbsolutePath("a:\\"), Is.True); Assert.That(SvnTools.IsAbsolutePath("A:\\"), Is.True); Assert.That(SvnTools.IsAbsolutePath("A:\\\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath("A:\\B"), Is.True); Assert.That(SvnTools.IsAbsolutePath("A:\\B\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath("a:/sdfsdfsd"), Is.True); Assert.That(SvnTools.IsAbsolutePath("A:\\dfsdfds"), Is.True); Assert.That(SvnTools.IsAbsolutePath("a:"), Is.False); Assert.That(SvnTools.IsAbsolutePath("A:file"), Is.False); Assert.That(Path.IsPathRooted("a:"), Is.True); Assert.That(Path.IsPathRooted("A:file"), Is.True); Assert.That(SvnTools.IsNormalizedFullPath(@"\\SERVER\path"), Is.False, @"\\SERVER\path"); Assert.That(SvnTools.IsNormalizedFullPath(@"\\server\path\"), Is.False, @"\\server\path\"); Assert.That(SvnTools.IsNormalizedFullPath(@"\\server\path"), Is.True, @"\\server\path"); Assert.That(SvnTools.IsNormalizedFullPath(@"\\server\Path"), Is.True, @"\\server\Path"); Assert.That(SvnTools.IsNormalizedFullPath(@"\\server\path\file"), Is.True); Assert.That(SvnTools.IsAbsolutePath(@"\\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path"), Is.True); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path\dir"), Is.True); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path\dir\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\path\dir\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\\server\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath(@"\server"), Is.False); }
public void Path_TestReallyLong() { string temp = Path.GetTempPath() + "\\" + Guid.NewGuid() + new String('a', 200); temp = temp.Replace("\\\\", "\\"); if (temp.Length < 256) { temp += "bbbbbbbbbbbbbbbbbbbb"; } Assert.That(CreateDirectory("\\\\?\\" + temp, IntPtr.Zero), Is.True, "Created directory {0}", temp); try { Assert.That(SvnTools.GetNormalizedFullPath(temp), Is.Not.Null, "Normalized path valid for extremely long path"); Assert.That(SvnTools.GetTruePath(temp), Is.Not.Null, "True path valid for extremely long path"); string t2 = temp.Replace("\\", "\\.\\"); Assert.That(SvnTools.GetNormalizedFullPath(t2), Is.EqualTo(SvnTools.GetNormalizedFullPath(temp)), "True path completed"); Assert.That(SvnTools.GetTruePath(t2), Is.EqualTo(SvnTools.GetTruePath(temp))); string sd = Guid.NewGuid().ToString() + ".tMp"; string notExisting = Path.Combine(temp, sd); string notExistingUpper = Path.Combine(temp.ToUpperInvariant(), sd); Assert.That(SvnTools.GetTruePath(notExistingUpper), Is.Null); Assert.That(SvnTools.GetTruePath(notExistingUpper, false), Is.Null); Assert.That(SvnTools.GetTruePath(notExistingUpper, true), Is.EqualTo(notExisting)); notExisting = Path.Combine(notExisting, "a\\b.tmp"); notExistingUpper = Path.Combine(notExistingUpper, "a\\b.tmp"); Assert.That(SvnTools.GetTruePath(notExistingUpper), Is.Null); Assert.That(SvnTools.GetTruePath(notExistingUpper, false), Is.Null); Assert.That(SvnTools.GetTruePath(notExistingUpper, true), Is.EqualTo(notExisting)); } finally { RemoveDirectory("\\\\?\\" + temp); } }
public void Path_FixCasing() { string path = MakeLong(_casedFile.ToUpperInvariant()); Assert.That(File.Exists(path), "Fixed path exists"); Assert.That(Path.GetFullPath(path), Is.Not.EqualTo(Path.GetFileName(_casedFile))); FileInfo fif = new FileInfo(path); Assert.That(fif.Name, Is.Not.EqualTo(Path.GetFileName(_casedFile))); Assert.That(Path.GetFileName(SvnTools.GetTruePath(path)), Is.EqualTo(Path.GetFileName(_casedFile))); string dir = SvnTools.GetTruePath(Path.GetDirectoryName(_casedFile)); Assert.That(SvnTools.GetTruePath(_casedFile.ToUpperInvariant()), Is.EqualTo(Path.Combine(dir, Path.GetFileName(_casedFile)))); Assert.That(SvnTools.GetTruePath("c:\\"), Is.EqualTo(SvnTools.GetTruePath("C:\\"))); Assert.That(SvnTools.GetTruePath("c:\\-never-exists-"), Is.EqualTo(SvnTools.GetTruePath("C:\\-never-exists-"))); }
public SvnItem GetAlreadyNormalizedItem(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } lock (_lock) { SvnItem item; if (!Map.TryGetValue(path, out item)) { var truePath = SvnTools.GetTruePath(path, true); // Just create an item based on his name. Delay the svn calls as long as we can StoreItem(item = new SvnItem(truePath ?? path, NoSccStatus.Unknown, SvnNodeKind.Unknown)); //item.MarkDirty(); // Load status on first access } return(item); } }
private void VerifySolutionNaming() { ThreadHelper.ThrowIfNotOnUIThread(); IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution)); string dir, path, user; if (sol == null || !VSErr.Succeeded(sol.GetSolutionInfo(out dir, out path, out user)) || string.IsNullOrEmpty(path)) { return; } string trueSln = SvnTools.GetTruePath(path, true) ?? SvnTools.GetNormalizedFullPath(path); if (trueSln == path) { return; // Nothing to do for us } IVsRunningDocumentTable rdt = GetService <IVsRunningDocumentTable>(typeof(SVsRunningDocumentTable)); if (rdt == null) { return; } Guid IID_hier = typeof(IVsHierarchy).GUID; IntPtr hier = IntPtr.Zero; IntPtr unk = Marshal.GetIUnknownForObject(sol); IntPtr ppunkDocData = IntPtr.Zero; try { IVsHierarchy slnHier; uint pitemid; uint pdwCookie; if (!VSErr.Succeeded(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_EditLock, path, out slnHier, out pitemid, out ppunkDocData, out pdwCookie))) { return; } if (!VSErr.Succeeded(Marshal.QueryInterface(unk, ref IID_hier, out hier))) { hier = IntPtr.Zero; return; } if (VSErr.Succeeded(rdt.RenameDocument(path, trueSln, hier, VSItemId.Root))) { int hr; hr = rdt.SaveDocuments((uint)(__VSRDTSAVEOPTIONS.RDTSAVEOPT_ForceSave | __VSRDTSAVEOPTIONS.RDTSAVEOPT_SaveNoChildren), slnHier, pitemid, pdwCookie); hr = sol.SaveSolutionElement((uint)(__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave), (IVsHierarchy)sol, pdwCookie); //GC.KeepAlive(hr); } if (ppunkDocData != IntPtr.Zero) { object doc = Marshal.GetObjectForIUnknown(ppunkDocData); } } finally { System.Runtime.InteropServices.Marshal.Release(unk); if (hier != IntPtr.Zero) { System.Runtime.InteropServices.Marshal.Release(hier); } if (ppunkDocData != IntPtr.Zero) { Marshal.Release(hier); } } }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } var walkPath = path; var walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } var args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { ISvnDirectoryUpdate updateDir; SvnItem walkItem = null; // We get more information for free, lets use that to update other items DirectoryMap.TryGetValue(walkPath, out var directory); if (null != directory) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one directory = new SvnDirectory(walkPath); updateDir = directory = GetDirectory(walkPath); DirectoryMap[walkPath] = directory; } bool ok; var statSelf = false; var noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf && null != walkItem) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { var truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!Map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
public void Path_NormalizePathSharp() { Assert.That(SvnTools.GetNormalizedFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\\"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), "Shortcut route via IsNormalized"); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf\\sad sad sad f\\"), Is.EqualTo("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf")); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); string drive = Environment.CurrentDirectory.Substring(0, 2).ToLowerInvariant(); Assert.That(SvnTools.GetNormalizedDirectoryName(drive), Is.EqualTo(drive.ToUpperInvariant() + Path.GetDirectoryName(Environment.CurrentDirectory).Substring(2))); // CWD on current drive Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("c:\\a"), Is.EqualTo("C:\\")); Assert.That(Path.GetDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\Server\Share")); Assert.That(Path.GetDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub\"), Is.EqualTo(@"C:\Dir\Sub")); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub"), Is.EqualTo(@"C:\Dir")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\server\Share")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$\\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\server\c$"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\seRver\c$\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\seRver\c$\\"), Is.Null); string share = @"\\" + Environment.MachineName.ToLowerInvariant() + @"\C$"; string shaUC = @"\\" + Environment.MachineName.ToUpperInvariant() + @"\C$"; Assert.That(SvnTools.IsNormalizedFullPath(share)); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC)); Assert.That(!SvnTools.IsNormalizedFullPath(share + "\\")); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC + "\\")); Assert.That(SvnTools.GetTruePath(share + "\\A\\B", true), Is.EqualTo(share + "\\A\\B")); Assert.That(SvnTools.GetTruePath(share + "\\A", true), Is.EqualTo(share + "\\A")); Assert.That(SvnTools.GetTruePath(share, true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath(share + "\\", true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath("C:\\A", true), Is.EqualTo("C:\\A")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); }
/// <summary> /// Fixes up missing files by fixing their casing or deleting them /// </summary> /// <param name="state">The state.</param> /// <returns></returns> private bool PreCommit_HandleMissingFiles(PendingCommitState state) { foreach (string path in new List <string>(state.CommitPaths)) { SvnItem item = state.Cache[path]; if (item.Status.LocalNodeStatus != SvnStatus.Missing) { continue; } if (item.IsCasingConflicted) { string correctCasing = GetSvnCasing(item); string actualCasing = SvnTools.GetTruePath(item.FullPath); if (correctCasing == null || actualCasing == null || !string.Equals(correctCasing, actualCasing, StringComparison.OrdinalIgnoreCase)) { continue; // Nothing to fix here :( } string correctFile = Path.GetFileName(correctCasing); string actualFile = Path.GetFileName(actualCasing); if (correctFile == actualFile) { continue; // Casing issue is not in the file; can't fix :( } IAnkhOpenDocumentTracker odt = GetService <IAnkhOpenDocumentTracker>(); using (odt.LockDocument(correctCasing, DocumentLockType.NoReload)) using (odt.LockDocument(actualCasing, DocumentLockType.NoReload)) { try { File.Move(actualCasing, correctCasing); // Fix the name in the commit list state.CommitPaths[state.CommitPaths.IndexOf(path)] = actualCasing; } catch { } finally { item.MarkDirty(); GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath); } } } else if (!item.Exists) { SvnDeleteArgs da = new SvnDeleteArgs(); da.KeepLocal = true; da.ThrowOnError = false; if (!state.Client.Delete(path, da)) { state.MessageBox.Show(da.LastException.Message, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } } } return(true); }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } string walkPath = path; bool walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } SvnStatusArgs args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { SvnDirectory directory; ISvnDirectoryUpdate updateDir; SvnItem walkItem; // We get more information for free, lets use that to update other items if (_dirMap.TryGetValue(walkPath, out directory)) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one updateDir = directory = new SvnDirectory(Context, walkPath); _dirMap[walkPath] = directory; } walkItem = directory.Directory; bool ok; bool statSelf = false; bool noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (!ok) { if (args.LastException != null) { switch (args.LastException.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT: if (CommandService != null) { CommandService.PostExecCommand(AnkhCommand.NotifyWcToNew, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED: _enableUpgrade = true; if (updateDir != null) { updateDir.SetNeedsUpgrade(); } if (!_sendUpgrade && CommandService != null) { _sendUpgrade = true; CommandService.PostExecCommand(AnkhCommand.NotifyUpgradeRequired, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY: // Status only reports this error if there is no ancestor working copy // We should avoid statting all parent directories again for .IsVersionable noWcAtAll = true; break; case SvnErrorCode.SVN_ERR_WC_CLEANUP_REQUIRED: if (updateDir != null) { updateDir.SetNeedsCleanup(); } break; } } statSelf = true; } else if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { string truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!_map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
public void Path_NormalizePathSharp() { Assert.That(SvnTools.GetNormalizedFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\\"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), "Shortcut route via IsNormalized"); if (File.Exists("C:\\Progra~1")) { Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\Progra~1"), Is.EqualTo("C:\\Program Files")); } Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf\\sad sad sad f\\"), Is.EqualTo("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf")); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); string drive = Environment.CurrentDirectory.Substring(0, 2).ToLowerInvariant(); var curDir = Environment.CurrentDirectory; if (curDir.Contains("~")) { // This case triggers on the GitHub bot curDir = SvnTools.GetNormalizedFullPath(curDir); } Assert.That(SvnTools.GetNormalizedDirectoryName(drive), Is.EqualTo(drive.ToUpperInvariant() + Path.GetDirectoryName(curDir).Substring(2))); // CWD on current drive Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("c:\\a"), Is.EqualTo("C:\\")); Assert.That(Path.GetDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\Server\Share")); Assert.That(Path.GetDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub\"), Is.EqualTo(@"C:\Dir\Sub")); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub"), Is.EqualTo(@"C:\Dir")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\server\Share")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$\\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\server\c$"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\seRver\c$\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\seRver\c$\\"), Is.Null); string share = @"\\" + Environment.MachineName.ToLowerInvariant() + @"\C$"; string shaUC = @"\\" + Environment.MachineName.ToUpperInvariant() + @"\C$"; Assert.That(SvnTools.IsNormalizedFullPath(share)); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC)); Assert.That(!SvnTools.IsNormalizedFullPath(share + "\\")); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC + "\\")); Assert.That(SvnTools.GetTruePath(share + "\\A\\B", true), Is.EqualTo(share + "\\A\\B")); Assert.That(SvnTools.GetTruePath(share + "\\A", true), Is.EqualTo(share + "\\A")); Assert.That(SvnTools.GetTruePath(share, true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath(share + "\\", true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath("C:\\A", true), Is.EqualTo("C:\\A")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedFullPath("c:\\"), Is.EqualTo("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\"), Is.EqualTo("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("C:"), Does.StartWith("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("c:"), Does.StartWith("C:\\")); }