在Windows下清理SVN关联文件

来源:互联网 发布:服务器攻击防御软件 编辑:程序博客网 时间:2024/04/29 19:59

        第一次写博文。

        前阵子笔记本的硬盘坏了,丢了很多的源代码。向公司反映此事,经批准搭设CVS服务器,一个便于追踪版本,一个以防类似以上的事故再次发生。但是实际搭设好CVS服务器后,发现有很多问题:

        第一,虽然使用了基于图形界面的WINCVS,但是上手还是很难,界面也不友好;

        第二,CVS无法实现强制版本。比如,XXX项目的版本提交到1.0.0.134 后,想统一所有文件的版本为2.0.0.0上继续开发,CVS无法实现。

        第三,CVS无法删除文件。如果你提交文件到服务器上以后,想再删除,不可能!

        所以,重新搭设了SVN服务器。据说是CVS的替代者,使用起来也很容易,界面友好,但还有很多外围的软件需要开发。比如SVN关联文件的清理:

1.制作背景:
        从SVN服务器上check out 工程文件之后,工程文件会产生关联文件,这对于追踪版本是必不可少的。但是,有时当我们需要将工程文件发送给其他人,或者拷贝到其他电脑上等等,此时我们并不想将工程文件夹内的关联文件一并发送,需要将目录下的_svn(或者.svn)文件手动地逐一删除。制作此程序就是为了方便清理关联文件.

2.程序实现方法:
        遍历工程文件下的所有文件和文件目录,如果是_svn(.svn)目录,则将该目录下的所有文件删除,并且删除_svn(.svn)目录;如果是其他目录,则通过递归,继续删除该目录下存在的_svn(.svn)目录及目录下的所有文件。
3.存在的问题:
        基本功能已经实现,但是_svn(.svn)目录无法删除,这可能与TSVNCache.exe进程有关。

 

int CSVNCLEANDlg::DeleteSVN(CString strPath)
{
    CString strFile;
    strFile.Format( 
"%s/*.*" , strPath );
    CFileFind finder;
    BOOL bWorking 
= finder.FindFile(strFile);
    
while (bWorking)
    
{
        bWorking 
= finder.FindNextFile();
        
        
// skip . and .. files; otherwise, we'd
        
// recur infinitely!
        
        
if (finder.IsDots())
            
continue;
        
        
// if it's a directory, recursively search it
        
        
if (finder.IsDirectory())
        
{
            CString str 
= finder.GetFileName();
            
if ( str == "_svn" || str == ".svn" )
            
{//SVN目录
                CString strTemp;
                strTemp.Format( 
"%s/%s" , strPath , str );
                AllDelete( strTemp );
            }

            
else
            
{
                CString strTemp;
                strTemp.Format( 
"%s/%s" ,m_strFolder, str );
                DeleteSVN( strTemp );
            }

            
//pBox->InsertString( iIndex , str );
            
//iIndex++;
        }

    }

    finder.Close();
    
return 0;
}


void CSVNCLEANDlg::AllDelete(CString strPath)
{
    CFileFind ff;
    CString path 
= strPath;
    
if ( path.Right(1!= "/")
    
{
        path 
+= "/";
    }

    path 
+= "*.*";
    BOOL res 
= ff.FindFile( path );
    
while (res)
    
{
        res 
= ff.FindNextFile();
        
if ( !ff.IsDots() && !ff.IsDirectory() )
        
{
            SetFileAttributes( ff.GetFilePath() , FILE_ATTRIBUTE_NORMAL );
            
if ( DeleteFile(ff.GetFilePath()) == 0 )
            
{
                TRACE(
"删除%s 失败 " , ff.GetFilePath() );
            }

        }

        
else if( ff.IsDots() )
        
{
            
continue;
        }

        
else if( ff.IsDirectory() )
        
{
            path 
= ff.GetFilePath();
            AllDelete( path );
            SetFileAttributes( ff.GetFilePath() , FILE_ATTRIBUTE_NORMAL );
            
if ( RemoveDirectory( path ) == 0 ) 
            
{
                TRACE(
"删除%s 失败 " , ff.GetFilePath() );
            }

        }

    }

    SetFileAttributes(strPath,   FILE_ATTRIBUTE_NORMAL);  
    RemoveDirectory(strPath);
    
//DWORD nCode = GetLastError();
}


原创粉丝点击