Beispiel #1
0
        /// <summary>
        /// Create a P4FileMap from the output of an fstat command
        /// </summary>
        /// <param name="pServer"></param>
        /// <param name="fstatInfo"></param>
        /// <returns></returns>
        public static P4FileMap FromFstatOutput(IList <FileMetaData> fileList)
        {
            if (fileList == null || fileList.Count <= 0)
            {
                return(null);
            }

            P4FileMap value = new P4FileMap();

            foreach (FileMetaData fsInfo in fileList)
            {
                value[fsInfo.GetFileName()] = fsInfo;
            }
            return(value);
        }
Beispiel #2
0
        /// <summary>
        /// Expand the directory by filling in the list of child directories
        /// and file within the directory.
        /// </summary>
        /// <returns>false if an error prevented completion</returns>
        public bool Expand(bool filtered)
        {
            if (String.IsNullOrEmpty(depotPath))
            {
                return(false);
            }

            if (_scm.ServerVersion >= Versions.V12_1)
            {
                if (!String.IsNullOrEmpty(depotPath))
                {
                    IList <string>       subdirs  = new List <string>();
                    IList <FileMetaData> fileList = new List <FileMetaData>();

                    Options options = new Options();
                    options["-Ol"] = null;
                    options["-D"]  = null;
                    options["-F"]  = "^headAction=delete & ^headAction=move/delete";
                    options["-T"]  = "depotFile, dir";

                    if (filtered)
                    {
                        options         = new Options();
                        options["-Ol"]  = null;
                        options["-Dlc"] = null;
                        options["-Rc"]  = null;
                        options["-F"]   = "^headAction=delete & ^headAction=move/delete";
                        options["-T"]   = "depotFile, dir";
                    }

                    IList <FileMetaData> fmd = _scm.GetFileMetaData(options, DepotPath + "/*");

                    foreach (FileMetaData f in fmd)
                    {
                        if (f.DepotPath != null)
                        {
                            fileList.Add(f);
                        }
                        if (f.Directory != null)
                        {
                            subdirs.Add(f.Directory);
                        }
                    }

                    if ((subdirs != null) && (subdirs.Count > 0))
                    {
                        subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs);
                        foreach (P4Directory dir in subdirectories.Values)
                        {
                            dir.InDepot = true;
                        }
                    }

                    if (fileList != null)
                    {
                        files = P4FileMap.FromFstatOutput(fileList);

                        // if the directory contains files from the depot, we can use
                        // the local path of one of those files to determine the local
                        // path for this directory
                        if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0))
                        {
                            foreach (FileMetaData f in files.Values)
                            {
                                if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path))
                                {
                                    localPath = f.LocalPath.GetDirectoryName();
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            else
            {
                // old tree builder using dirs and fstat
                //*****************************************************************************************
                // if we have the depot path, get a list of the subdirectories from the depot
                if (!String.IsNullOrEmpty(depotPath))
                {
                    IList <string> subdirs = _scm.GetDepotDirs(null, String.Format("{0}/*", depotPath));
                    if ((subdirs != null) && (subdirs.Count > 0))
                    {
                        subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs);
                        foreach (P4Directory dir in subdirectories.Values)
                        {
                            dir.InDepot = true;
                        }
                    }

                    IList <FileMetaData> fileList = _scm.GetFileMetaData(null, String.Format("{0}/*", depotPath));
                    // get a list of the files in the directory

                    if (fileList != null)
                    {
                        files = P4FileMap.FromFstatOutput(fileList);

                        // if the directory contains files from the depot, we can use
                        // the local path of one of those files to determine the local
                        // path for this directory
                        if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0))
                        {
                            foreach (FileMetaData f in files.Values)
                            {
                                if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path))
                                {
                                    localPath = f.LocalPath.GetDirectoryName();
                                    break;
                                }
                            }
                        }
                    }
                }
                //*****************************************************************************************
            }



            // if we have a workspace and a local path, match the files and
            // subdirectories in the depot with the files in the file system
            if ((!String.IsNullOrEmpty(localPath)) && (Workspace != null))
            {
                DirectoryInfo[] directoryList = null;
                FileInfo[]      fileList      = null;
                try
                {
                    DirectoryInfo di = new DirectoryInfo(localPath);

                    directoryList = di.GetDirectories();
                    fileList      = di.GetFiles();
                }
                catch
                {
                    //LogFile.LogException( "Initializing Directory from Workspace", ex );
                }

                // get the subdirectories listed in the file and match them up
                // with the one in the list from the depot
                if ((directoryList != null) && (directoryList.Length > 0))
                {
                    foreach (DirectoryInfo di in directoryList)
                    {
                        string itemName = di.Name;
                        if (subdirectories.ContainsKey(itemName))
                        {
                            subdirectories[itemName].InWorkspace = true;
                        }
                        else
                        {
                            P4Directory subDir = new P4Directory(_scm, Workspace, itemName, null, di.FullName, parentDirectory);
                            subDir.InDepot           = false;
                            subDir.InWorkspace       = true;
                            subdirectories[itemName] = subDir;
                        }
                    }
                }

                // get the files listed in the subdirectory and match them up
                // with the one in the list from the depot
                if ((fileList != null) && (fileList.Length > 0))
                {
                    foreach (FileInfo fi in fileList)
                    {
                        string itemName = fi.Name;
                        if (files != null && files.ContainsKey(itemName) == false)
                        {
                            FileMetaData file = new FileMetaData();
                            file.LocalPath  = new LocalPath(fi.FullName);
                            file.DepotPath  = null;
                            file.FileSize   = fi.Length;
                            files[itemName] = file;
                        }
                    }
                }
            }
            return(true);
        }