private static bool ValidateVCSFiles(IEnumerable <string> files, string tempOutputPath)
        {
            var assetList = new AssetList();

            foreach (string f in files)
            {
                assetList.Add(Provider.GetAssetByPath(f.Replace(tempOutputPath, "")));
            }

            // Verify that all the files are also in assetList
            // This is required to ensure the copy temp files to destination loop is only working on version controlled files
            // Provider.GetAssetByPath() can fail i.e. the asset database GUID can not be found for the input asset path
            foreach (var f in files)
            {
                var rawAssetPath = f.Replace(tempOutputPath, "");
                // VCS assets path separator is '/' , file path might be '\' or '/'
                var assetPath  = (Path.DirectorySeparatorChar == '\\') ? rawAssetPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) : rawAssetPath;
                var foundAsset = assetList.Where(asset => (asset.path == assetPath));
                if (!foundAsset.Any())
                {
                    Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to add file to list): {0}", rawAssetPath);
                    APIUpdaterManager.ReportExpectedUpdateFailure();
                    return(false);
                }
            }

            var checkoutTask = Provider.Checkout(assetList, CheckoutMode.Exact);

            checkoutTask.Wait();

            // Verify that all the files we need to operate on are now editable according to version control
            // One of these states:
            // 1) UnderVersionControl & CheckedOutLocal
            // 2) UnderVersionControl & AddedLocal
            // 3) !UnderVersionControl
            var notEditable = assetList.Where(asset => asset.IsUnderVersionControl && !asset.IsState(Asset.States.CheckedOutLocal) && !asset.IsState(Asset.States.AddedLocal));

            if (!checkoutTask.success || notEditable.Any())
            {
                Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to check out): {0}", notEditable.Select(a => a.fullName + " (" + a.state + ")").Aggregate((acc, curr) => acc + Environment.NewLine + "\t" + curr));
                APIUpdaterManager.ReportExpectedUpdateFailure();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        internal static bool CheckoutAndValidateVCSFiles(IEnumerable <string> files)
        {
            // We're only interested in files that would be under VCS, i.e. project
            // assets or local packages. Incoming paths might use backward slashes; replace with
            // forward ones as that's what Unity/VCS functions operate on.
            files = files.Select(f => f.Replace('\\', '/')).Where(Provider.PathIsVersioned).ToArray();

            var assetList = new AssetList();

            assetList.AddRange(files.Select(Provider.GetAssetByPath));

            // Verify that all the files are also in assetList
            // This is required to ensure the copy temp files to destination loop is only working on version controlled files
            // Provider.GetAssetByPath() can fail i.e. the asset database GUID can not be found for the input asset path
            foreach (var assetPath in files)
            {
                var foundAsset = assetList.Where(asset => (asset?.path == assetPath));
                if (!foundAsset.Any())
                {
                    Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to add file to list): {0}", assetPath);
                    APIUpdaterManager.ReportExpectedUpdateFailure();
                    return(false);
                }
            }

            var checkoutTask = Provider.Checkout(assetList, CheckoutMode.Exact);

            checkoutTask.Wait();

            // Verify that all the files we need to operate on are now editable according to version control
            // One of these states:
            // 1) UnderVersionControl & CheckedOutLocal
            // 2) UnderVersionControl & AddedLocal
            // 3) !UnderVersionControl
            var notEditable = assetList.Where(asset => asset.IsUnderVersionControl && !asset.IsState(Asset.States.CheckedOutLocal) && !asset.IsState(Asset.States.AddedLocal));

            if (!checkoutTask.success || notEditable.Any())
            {
                Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to check out): {0}", notEditable.Select(a => a.fullName + " (" + a.state + ")").Aggregate((acc, curr) => acc + Environment.NewLine + "\t" + curr));
                APIUpdaterManager.ReportExpectedUpdateFailure();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private static void UpdateFilesInVCIfNeeded()
        {
            if (!Provider.enabled)
            {
                return;
            }

            var files = Directory.GetFiles(tempOutputPath, "*.*", SearchOption.AllDirectories);

            var assetList = new AssetList();

            foreach (string f in files)
            {
                assetList.Add(Provider.GetAssetByPath(f.Replace(tempOutputPath, "")));
            }

            // Verify that all the files are also in assetList
            // This is required to ensure the copy temp files to destination loop is only working on version controlled files
            // Provider.GetAssetByPath() can fail i.e. the asset database GUID can not be found for the input asset path
            foreach (var f in files)
            {
                var rawAssetPath = f.Replace(tempOutputPath, "");
                // VCS assets path separator is '/' , file path might be '\' or '/'
                var assetPath  = (Path.DirectorySeparatorChar == '\\') ? rawAssetPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) : rawAssetPath;
                var foundAsset = assetList.Where(asset => (asset.path == assetPath));
                if (!foundAsset.Any())
                {
                    Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to add file to list): {0}", rawAssetPath);
                    ScriptUpdatingManager.ReportExpectedUpdateFailure();
                    return;
                }
            }

            var checkoutTask = Provider.Checkout(assetList, CheckoutMode.Exact);

            checkoutTask.Wait();

            // Verify that all the files we need to operate on are now editable according to version control
            // One of these states:
            // 1) UnderVersionControl & CheckedOutLocal
            // 2) UnderVersionControl & AddedLocal
            // 3) !UnderVersionControl
            var notEditable = assetList.Where(asset => asset.IsUnderVersionControl && !asset.IsState(Asset.States.CheckedOutLocal) && !asset.IsState(Asset.States.AddedLocal));

            if (!checkoutTask.success || notEditable.Any())
            {
                Debug.LogErrorFormat("[API Updater] Files cannot be updated (failed to check out): {0}", notEditable.Select(a => a.fullName + " (" + a.state + ")").Aggregate((acc, curr) => acc + Environment.NewLine + "\t" + curr));
                ScriptUpdatingManager.ReportExpectedUpdateFailure();
                return;
            }

            // Verify that all the files we need to copy are now writable
            // Problems after API updating during ScriptCompilation if the files are not-writable
            notEditable = assetList.Where(asset => ((File.GetAttributes(asset.path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly));
            if (notEditable.Any())
            {
                Debug.LogErrorFormat("[API Updater] Files cannot be updated (files not writable): {0}", notEditable.Select(a => a.fullName).Aggregate((acc, curr) => acc + Environment.NewLine + "\t" + curr));
                ScriptUpdatingManager.ReportExpectedUpdateFailure();
                return;
            }

            // Copy the temp files to the destination : note this operates on "files"
            // Earlier have verified a one-to-one correspondence between assetList and "files"
            foreach (var sourceFileName in files)
            {
                var destFileName = sourceFileName.Replace(tempOutputPath, "");
                File.Copy(sourceFileName,  destFileName, true);
            }
            FileUtil.DeleteFileOrDirectory(tempOutputPath);
        }