[SRC] [C#] [SVN] Hard link файлов проекта без SVN информации
От: adontz Грузия http://adontz.wordpress.com/
Дата: 20.04.06 00:32
Оценка:
Вобщем понадобилось иметь один проект в двух репозиториях. svn:externals использовать было нельзя. На синхронность ревизий было глубоко наплевать. А вот править одни и те же файлы по два раза не хотелось. В результате родилось вот это.
using System;
using System.Runtime.InteropServices;
using System.IO;

namespace DeepHardLink
{
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern bool CreateHardLink(string pathDestination, string pathSource, IntPtr lpSecurityAttributes);
        
        static int rootLength = 0;
        
        static void DeepCopy(string pathSource, string pathDestination)
        {
            DirectoryInfo dirInfoSource = new DirectoryInfo(pathSource);
            DirectoryInfo dirInfoDestination = new DirectoryInfo(pathDestination);
            
            foreach (DirectoryInfo dirInfo in dirInfoSource.GetDirectories())
            {
                if (!dirInfo.Name.StartsWith(".svn"))
                {
                    string subPathSource = pathSource + "\\" + dirInfo.Name;
                    string subPathDestination = pathDestination + "\\" + dirInfo.Name;

                    if (!Directory.Exists(subPathDestination))
                    {
                        Directory.CreateDirectory(subPathDestination);
                    }
                    
                    DeepCopy(subPathSource, subPathDestination);
                }
            }
            
            foreach (FileInfo fileInfo in dirInfoSource.GetFiles())
            {
                string subPathSource = pathSource + "\\" + fileInfo.Name;
                string subPathDestination = pathDestination + "\\" + fileInfo.Name;
                
                if (!File.Exists(subPathDestination))
                {
                    if (CreateHardLink(subPathDestination, subPathSource, IntPtr.Zero))
                    {
                        Console.WriteLine("OK:     \"{0}\"", subPathSource.Substring(rootLength));
                    }
                    else
                    {
                        Console.WriteLine("FAILED: \"{0}\"", subPathSource.Substring(rootLength));
                    }
                }
                else
                {
                    Console.WriteLine("SKIPED: \"{0}\"", subPathSource.Substring(rootLength));
                }
            }
        }
        
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: DeepHardLink.exe source\\dir destination\\dir");
            }
            else
            {
                rootLength = args[0].Length;
                
                DeepCopy(args[0], args[1]);
            }
        }
    }
}

Кто считает, что я поступил неправильно идите в лес Остальмым приятного просмотра.
A journey of a thousand miles must begin with a single step © Lau Tsu
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.