Пример #1
0
        public virtual Result UpdatePlaceholderIfNeeded(
            string relativePath,
            byte[] providerId,
            byte[] contentId,
            ushort fileMode,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            if (providerId.Length != Interop.PrjFSLib.PlaceholderIdLength ||
                contentId.Length != Interop.PrjFSLib.PlaceholderIdLength)
            {
                throw new ArgumentException();
            }

            UpdateFailureCause updateFailureCause = UpdateFailureCause.NoFailure;
            Result             result             = Interop.PrjFSLib.UpdatePlaceholderFileIfNeeded(
                relativePath,
                providerId,
                contentId,
                fileMode,
                updateFlags,
                ref updateFailureCause);

            failureCause = updateFailureCause;
            return(result);
        }
Пример #2
0
        public override FileSystemResult UpdatePlaceholderIfNeeded(
            string relativePath,
            DateTime creationTime,
            DateTime lastAccessTime,
            DateTime lastWriteTime,
            DateTime changeTime,
            uint fileAttributes,
            long endOfFile,
            string shaContentId,
            UpdatePlaceholderType updateFlags,
            out UpdateFailureReason failureReason)
        {
            UpdateFailureCause failureCause = UpdateFailureCause.NoFailure;

            // TODO(Mac): Add functional tests that include:
            //     - Mode + content changes between commits
            //     - Mode only changes (without any change to content, see issue #223)
            ushort fileMode = this.FileSystemCallbacks.GitIndexProjection.GetFilePathMode(relativePath);

            Result result = this.virtualizationInstance.UpdatePlaceholderIfNeeded(
                relativePath,
                PlaceholderVersionId,
                ToVersionIdByteArray(ConvertShaToContentId(shaContentId)),
                (ulong)endOfFile,
                fileMode,
                (UpdateType)updateFlags,
                out failureCause);

            failureReason = (UpdateFailureReason)failureCause;
            return(new FileSystemResult(ResultToFSResult(result), unchecked ((int)result)));
        }
Пример #3
0
 public virtual Result UpdatePlaceholderIfNeeded(
     string relativePath,
     byte[] providerId,
     byte[] contentId,
     ulong fileSize,
     uint fileMode,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     /*
      * if (providerId.Length != ProjFS.PlaceholderIdLength ||
      *  contentId.Length != ProjFS.PlaceholderIdLength)
      * {
      *  throw new ArgumentException();
      * }
      *
      * UpdateFailureCause updateFailureCause = UpdateFailureCause.NoFailure;
      * Result result = ProjFS.UpdatePlaceholderFileIfNeeded(
      *  relativePath,
      *  providerId,
      *  contentId,
      *  fileSize,
      *  fileMode,
      *  updateFlags,
      *  ref updateFailureCause);
      *
      * failureCause = updateFailureCause;
      * return result;
      */
     failureCause = UpdateFailureCause.NoFailure;
     return(Result.ENotYetImplemented);
 }
Пример #4
0
        public virtual Result UpdatePlaceholderIfNeeded(
            string relativePath,
            byte[] providerId,
            byte[] contentId,
            ulong fileSize,
            uint fileMode,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            if (providerId.Length != PlaceholderIdLength ||
                contentId.Length != PlaceholderIdLength)
            {
                throw new ArgumentException();
            }

            Result result = this.DeleteFile(relativePath, updateFlags, out failureCause);

            if (result != Result.Success)
            {
                return(result);
            }

            // TODO(Linux): try to handle races with hydration?
            failureCause = UpdateFailureCause.NoFailure;
            return(this.WritePlaceholderFile(relativePath, providerId, contentId, fileSize, fileMode));
        }
Пример #5
0
 public virtual Result DeleteFile(
     string relativePath,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     throw new NotImplementedException();
 }
 public override Result DeleteFile(
     string relativePath,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     failureCause = this.DeleteFileUpdateFailureCause;
     return(this.DeleteFileResult);
 }
        public virtual Result DeleteFile(
            string relativePath,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            failureCause = UpdateFailureCause.NoFailure;

            if (!this.ObtainProjFS(out ProjFS fs))
            {
                return(Result.EDriverNotLoaded);
            }

            if (string.IsNullOrEmpty(relativePath))
            {
                /* Our mount point directory can not be deleted; we would
                 * receive an EBUSY error.  Therefore we just return
                 * EDirectoryNotEmpty because that error is silently handled
                 * by our caller in GitIndexProjection, and this is the
                 * expected behavior (corresponding to the Mac implementation).
                 */
                return(Result.EDirectoryNotEmpty);
            }

            string fullPath    = Path.Combine(this.virtualizationRoot, relativePath);
            bool   isDirectory = Directory.Exists(fullPath);
            Result result      = Result.Success;

            if (!isDirectory)
            {
                // TODO(Linux): try to handle races with hydration?
                ProjectionState state;
                result = fs.GetProjState(relativePath, out state);

                // also treat unknown state as full/dirty (e.g., for sockets)
                if ((result == Result.Success && state == ProjectionState.Full) ||
                    (result == Result.Invalid && state == ProjectionState.Unknown))
                {
                    failureCause = UpdateFailureCause.DirtyData;
                    return(Result.EVirtualizationInvalidOperation);
                }
            }

            if (result == Result.Success)
            {
                result = RemoveFileOrDirectory(fullPath, isDirectory);
            }

            if (result == Result.EAccessDenied)
            {
                failureCause = UpdateFailureCause.ReadOnly;
            }
            else if (result == Result.EFileNotFound || result == Result.EPathNotFound)
            {
                return(Result.Success);
            }

            return(result);
        }
 public static extern Result UpdatePlaceholderFileIfNeeded(
     string relativePath,
     [MarshalAs(UnmanagedType.LPArray, SizeConst = PlaceholderIdLength)]
     byte[] providerId,
     [MarshalAs(UnmanagedType.LPArray, SizeConst = PlaceholderIdLength)]
     byte[] contentId,
     ushort fileMode,
     UpdateType updateType,
     ref UpdateFailureCause failureCause);
Пример #9
0
 public virtual Result UpdatePlaceholderIfNeeded(
     string relativePath,
     byte[] providerId,
     byte[] contentId,
     ulong fileSize,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     throw new NotImplementedException();
 }
 public override Result ReplacePlaceholderFileWithSymLink(
     string relativePath,
     string symLinkTarget,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     this.CreatedSymLinks.Add(relativePath);
     failureCause = this.UpdatePlaceholderIfNeededFailureCause;
     return(this.UpdatePlaceholderIfNeededResult);
 }
 public override Result UpdatePlaceholderIfNeeded(
     string relativePath,
     byte[] providerId,
     byte[] contentId,
     ulong fileSize,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     failureCause = this.UpdatePlaceholderIfNeededFailureCause;
     return(this.UpdatePlaceholderIfNeededResult);
 }
Пример #12
0
        public virtual Result DeleteFile(
            string relativePath,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            UpdateFailureCause deleteFailureCause = UpdateFailureCause.NoFailure;
            Result             result             = Interop.PrjFSLib.DeleteFile(
                relativePath,
                updateFlags,
                ref deleteFailureCause);

            failureCause = deleteFailureCause;
            return(result);
        }
        public override Result UpdatePlaceholderIfNeeded(
            string relativePath,
            byte[] providerId,
            byte[] contentId,
            ushort fileMode,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            failureCause = this.UpdatePlaceholderIfNeededFailureCause;
            if (failureCause == UpdateFailureCause.NoFailure)
            {
                this.UpdatedPlaceholders[relativePath] = fileMode;
            }

            return(this.UpdatePlaceholderIfNeededResult);
        }
Пример #14
0
        public virtual Result ReplacePlaceholderFileWithSymLink(
            string relativePath,
            string symLinkTarget,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            UpdateFailureCause updateFailureCause = UpdateFailureCause.NoFailure;
            Result             result             = Interop.PrjFSLib.ReplacePlaceholderFileWithSymLink(
                relativePath,
                symLinkTarget,
                updateFlags,
                ref updateFailureCause);

            failureCause = updateFailureCause;
            return(result);
        }
Пример #15
0
        public virtual Result ReplacePlaceholderFileWithSymLink(
            string relativePath,
            string symLinkTarget,
            UpdateType updateFlags,
            out UpdateFailureCause failureCause)
        {
            Result result = this.DeleteFile(relativePath, updateFlags, out failureCause);

            if (result != Result.Success)
            {
                return(result);
            }

            // TODO(Linux): try to handle races with hydration?
            failureCause = UpdateFailureCause.NoFailure;
            return(this.WriteSymLink(relativePath, symLinkTarget));
        }
Пример #16
0
 public virtual Result DeleteFile(
     string relativePath,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     /*
      * UpdateFailureCause deleteFailureCause = UpdateFailureCause.NoFailure;
      * Result result = ProjFS.DeleteFile(
      *  relativePath,
      *  updateFlags,
      *  ref deleteFailureCause);
      *
      * failureCause = deleteFailureCause;
      * return result;
      */
     failureCause = UpdateFailureCause.NoFailure;
     return(Result.ENotYetImplemented);
 }
Пример #17
0
 public virtual Result ReplacePlaceholderFileWithSymLink(
     string relativePath,
     string symLinkTarget,
     UpdateType updateFlags,
     out UpdateFailureCause failureCause)
 {
     /*
      * UpdateFailureCause updateFailureCause = UpdateFailureCause.NoFailure;
      * Result result = ProjFS.ReplacePlaceholderFileWithSymLink(
      *  relativePath,
      *  symLinkTarget,
      *  updateFlags,
      *  ref updateFailureCause);
      *
      * failureCause = updateFailureCause;
      * return result;
      */
     failureCause = UpdateFailureCause.NoFailure;
     return(Result.ENotYetImplemented);
 }
        public override FileSystemResult UpdatePlaceholderIfNeeded(
            string relativePath,
            DateTime creationTime,
            DateTime lastAccessTime,
            DateTime lastWriteTime,
            DateTime changeTime,
            uint fileAttributes,
            long endOfFile,
            string shaContentId,
            UpdatePlaceholderType updateFlags,
            out UpdateFailureReason failureReason)
        {
            UpdateFailureCause failureCause = UpdateFailureCause.NoFailure;
            Result             result       = this.virtualizationInstance.UpdatePlaceholderIfNeeded(
                relativePath,
                GetPlaceholderVersionId(),
                ConvertShaToContentId(shaContentId),
                (ulong)endOfFile,
                (UpdateType)updateFlags,
                out failureCause);

            failureReason = (UpdateFailureReason)failureCause;
            return(new FileSystemResult(ResultToFSResult(result), unchecked ((int)result)));
        }
Пример #19
0
 public static extern Result ReplacePlaceholderFileWithSymLink(
     string relativePath,
     string symLinkTarget,
     UpdateType updateType,
     ref UpdateFailureCause failureCause);
 public HResult UpdateFileIfNeeded(string relativePath, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, DateTime changeTime, FileAttributes fileAttributes, long endOfFile, byte[] contentId, byte[] providerId, UpdateType updateFlags, out UpdateFailureCause failureReason)
 {
     failureReason = this.UpdateFileIfNeededFailureCase;
     return(this.UpdateFileIfNeededResult);
 }
Пример #21
0
 public HResult UpdatePlaceholderIfNeeded(string relativePath, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, DateTime changeTime, uint fileAttributes, long endOfFile, byte[] contentId, byte[] epochId, UpdateType updateFlags, ref UpdateFailureCause failureReason)
 {
     throw new NotImplementedException();
 }
Пример #22
0
 public HResult DeleteFile(string relativePath, UpdateType updateFlags, ref UpdateFailureCause failureReason)
 {
     throw new NotImplementedException();
 }
        /// <param name="endOfFile">Length of the file, not required on the Mac platform</param>
        public override FileSystemResult UpdatePlaceholderIfNeeded(
            string relativePath,
            DateTime creationTime,
            DateTime lastAccessTime,
            DateTime lastWriteTime,
            DateTime changeTime,
            FileAttributes fileAttributes,
            long endOfFile,
            string shaContentId,
            UpdatePlaceholderType updateFlags,
            out UpdateFailureReason failureReason)
        {
            UpdateFailureCause failureCause = UpdateFailureCause.NoFailure;

            // TODO(#223): Add functional tests that include:
            //     - Mode + content changes between commits
            //     - Mode only changes (without any change to content, see issue #223)
            GitIndexProjection.FileType fileType;
            ushort fileMode;

            this.FileSystemCallbacks.GitIndexProjection.GetFileTypeAndMode(relativePath, out fileType, out fileMode);

            if (fileType == GitIndexProjection.FileType.Regular)
            {
                Result result = this.virtualizationInstance.UpdatePlaceholderIfNeeded(
                    relativePath,
                    PlaceholderVersionId,
                    ToVersionIdByteArray(ConvertShaToContentId(shaContentId)),
                    fileMode,
                    (UpdateType)updateFlags,
                    out failureCause);

                failureReason = (UpdateFailureReason)failureCause;
                return(new FileSystemResult(ResultToFSResult(result), unchecked ((int)result)));
            }
            else if (fileType == GitIndexProjection.FileType.SymLink)
            {
                string symLinkTarget;
                if (this.TryGetSymLinkTarget(shaContentId, out symLinkTarget))
                {
                    Result result = this.virtualizationInstance.ReplacePlaceholderFileWithSymLink(
                        relativePath,
                        symLinkTarget,
                        (UpdateType)updateFlags,
                        out failureCause);

                    this.FileSystemCallbacks.OnFileSymLinkCreated(relativePath);

                    failureReason = (UpdateFailureReason)failureCause;
                    return(new FileSystemResult(ResultToFSResult(result), unchecked ((int)result)));
                }

                EventMetadata metadata = this.CreateEventMetadata(relativePath);
                metadata.Add(nameof(shaContentId), shaContentId);
                this.Context.Tracer.RelatedError(metadata, $"{nameof(this.UpdatePlaceholderIfNeeded)}: Failed to read contents of symlink object");
                failureReason = UpdateFailureReason.NoFailure;
                return(new FileSystemResult(FSResult.IOError, 0));
            }
            else
            {
                EventMetadata metadata = this.CreateEventMetadata(relativePath);
                metadata.Add(nameof(fileType), fileType);
                metadata.Add(nameof(fileMode), fileMode);
                this.Context.Tracer.RelatedError(metadata, $"{nameof(this.UpdatePlaceholderIfNeeded)}: Unsupported fileType");
                failureReason = UpdateFailureReason.NoFailure;
                return(new FileSystemResult(FSResult.IOError, 0));
            }
        }
Пример #24
0
 public static extern Result DeleteFile(
     string relativePath,
     UpdateType updateType,
     ref UpdateFailureCause failureCause);
        public void InvokeUpdatePlaceholderIfNeeded(string fileName, FileSystemResult expectedResult, UpdateFailureCause expectedFailureCause)
        {
            UpdateFailureReason failureReason = UpdateFailureReason.NoFailure;

            this.MacVirtualizer.UpdatePlaceholderIfNeeded(
                fileName,
                DateTime.Now,
                DateTime.Now,
                DateTime.Now,
                DateTime.Now,
                0,
                15,
                string.Empty,
                UpdatePlaceholderType.AllowReadOnly,
                out failureReason)
            .ShouldEqual(expectedResult);
            failureReason.ShouldEqual((UpdateFailureReason)expectedFailureCause);
        }