private void SetHasWorkOrFinished()
        {
            if (this.expectOffset == this.SharedTransferData.TotalLength)
            {
                Exception ex = null;
                if (this.md5HashStream.CheckMd5Hash && this.md5HashStream.SucceededSeparateMd5Calculator)
                {
                    string calculatedMd5 = this.md5HashStream.MD5HashTransformFinalBlock();

                    string storedMd5 = this.SharedTransferData.Attributes.ContentMD5;

                    if (!calculatedMd5.Equals(storedMd5))
                    {
                        ex = new InvalidOperationException(
                            string.Format(
                                CultureInfo.CurrentCulture,
                                Resources.DownloadedMd5MismatchException,
                                this.TransferJob.Source.ToString(),
                                calculatedMd5,
                                storedMd5));
                    }
                }

                this.CloseOwnedOutputStream();

                if (this.TransferJob.Transfer.PreserveSMBAttributes)
                {
                    if (this.SharedTransferData.Attributes.CloudFileNtfsAttributes.HasValue &&
                        !string.IsNullOrEmpty(this.filePath))
                    {
                        LongPathFile.SetFileTime(this.filePath, this.SharedTransferData.Attributes.CreationTime.Value, this.SharedTransferData.Attributes.LastWriteTime.Value);
                        LongPathFile.SetAttributes(this.filePath, Utils.AzureFileNtfsAttributesToLocalAttributes(this.SharedTransferData.Attributes.CloudFileNtfsAttributes.Value));
                    }
                }

                if ((PreserveSMBPermissions.None != this.TransferJob.Transfer.PreserveSMBPermissions) &&
                    (!string.IsNullOrEmpty(this.SharedTransferData.Attributes.PortableSDDL)))
                {
                    if (!string.IsNullOrEmpty(this.filePath))
                    {
                        FileSecurityOperations.SetFileSecurity(
                            this.filePath,
                            this.SharedTransferData.Attributes.PortableSDDL,
                            this.TransferJob.Transfer.PreserveSMBPermissions);
                    }
                }

                this.NotifyFinished(ex);
                this.state = State.Finished;
            }
            else
            {
                this.hasWork = true;
            }
        }
 public static void SetFileSecurityInfo(string path, string portableSDDL, PreserveSMBPermissions preserveSMBPermissions)
 {
     try
     {
         path = DMLibTestConstants.SupportUNCPath ?
                LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                LongPath.GetFullPath(path);
     }
     catch (Exception)
     { }
     FileSecurityOperations.SetFileSecurity(path, portableSDDL, preserveSMBPermissions);
 }
 public static string GetFilePortableSDDL(string path, PreserveSMBPermissions preserveSMBPermissions)
 {
     try
     {
         path = DMLibTestConstants.SupportUNCPath ?
                LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                LongPath.GetFullPath(path);
     }
     catch (Exception)
     { }
     return(FileSecurityOperations.GetFilePortableSDDL(path, preserveSMBPermissions));
 }
예제 #4
0
        private void SetChunkFinish()
        {
            if (1 == Interlocked.Read(ref this.readCompleted))
            {
                if (0 == Interlocked.Exchange(ref this.setCompletionDone, 1))
                {
                    this.state = State.Finished;
                    if (!this.md5HashStream.SucceededSeparateMd5Calculator)
                    {
                        return;
                    }

                    var md5 = this.md5HashStream.MD5HashTransformFinalBlock();
                    this.CloseOwnStream();

                    Attributes attributes = new Attributes()
                    {
                        ContentMD5   = md5,
                        OverWriteAll = false
                    };

                    if (this.transferJob.Transfer.PreserveSMBAttributes)
                    {
                        if (!string.IsNullOrEmpty(this.filePath))
                        {
                            DateTimeOffset?creationTime;
                            DateTimeOffset?lastWriteTime;
                            FileAttributes?fileAttributes;

                            LongPathFile.GetFileProperties(this.filePath, out creationTime, out lastWriteTime, out fileAttributes);

                            attributes.CloudFileNtfsAttributes = Utils.LocalAttributesToAzureFileNtfsAttributes(fileAttributes.Value);
                            attributes.CreationTime            = creationTime;
                            attributes.LastWriteTime           = lastWriteTime;
                        }
                    }

                    if (PreserveSMBPermissions.None != this.transferJob.Transfer.PreserveSMBPermissions)
                    {
                        if (!string.IsNullOrEmpty(this.filePath))
                        {
                            attributes.PortableSDDL = FileSecurityOperations.GetFilePortableSDDL(filePath, this.transferJob.Transfer.PreserveSMBPermissions);
                        }
                    }

                    this.SharedTransferData.Attributes = attributes;
                }
            }
        }
예제 #5
0
 public static void SetFileSecurityInfo(string path, string portableSDDL, PreserveSMBPermissions preserveSMBPermissions)
 {
     FileSecurityOperations.SetFileSecurity(path, portableSDDL, preserveSMBPermissions);
 }
예제 #6
0
 public static string GetFilePortableSDDL(string path, PreserveSMBPermissions preserveSMBPermissions)
 {
     return(FileSecurityOperations.GetFilePortableSDDL(path, preserveSMBPermissions));
 }