Example #1
0
        private Guid WriteOrUseUuidIfSupported(IFileSystemInfo localFile)
        {
            Guid uuid = Guid.Empty;

            if (localFile.IsExtendedAttributeAvailable())
            {
                try {
                    string ea = localFile.GetExtendedAttribute(MappedObject.ExtendedAttributeKey);
                    if (ea == null || !Guid.TryParse(ea, out uuid) || this.Storage.GetObjectByGuid(uuid) != null)
                    {
                        uuid = Guid.NewGuid();
                        localFile.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, uuid.ToString(), true);
                    }
                } catch (ExtendedAttributeException ex) {
                    throw new RetryException(ex.Message, ex);
                }
            }

            return(uuid);
        }
Example #2
0
        private bool DeleteLocalObjectIfHasBeenSyncedBefore(IMetaDataStorage storage, IFileSystemInfo fsInfo)
        {
            bool          delete = true;
            string        reason;
            Guid          uuid;
            IMappedObject obj = null;

            if (Guid.TryParse(fsInfo.GetExtendedAttribute(MappedObject.ExtendedAttributeKey), out uuid))
            {
                obj = storage.GetObjectByGuid(uuid);
            }
            else
            {
                obj = storage.GetObjectByLocalPath(fsInfo);
            }

            if (fsInfo is IFileInfo)
            {
                if (obj != null && fsInfo.LastWriteTimeUtc.Equals(obj.LastLocalWriteTimeUtc))
                {
                    (fsInfo as IFileInfo).Delete();
                    OperationsLogger.Info(string.Format("Deleted local file {0} because the mapped remote object {0} has been deleted", fsInfo.FullName, obj.RemoteObjectId));
                }
                else
                {
                    fsInfo.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, null, true);
                    return(false);
                }
            }
            else if (fsInfo is IDirectoryInfo)
            {
                var dir = fsInfo as IDirectoryInfo;
                if (!this.filters.FolderNamesFilter.CheckFolderName(dir.Name, out reason))
                {
                    foreach (var folder in dir.GetDirectories())
                    {
                        if (!this.DeleteLocalObjectIfHasBeenSyncedBefore(storage, folder))
                        {
                            delete = false;
                        }
                    }

                    foreach (var file in dir.GetFiles())
                    {
                        if (!this.filters.FileNamesFilter.CheckFile(file.Name, out reason))
                        {
                            if (!this.DeleteLocalObjectIfHasBeenSyncedBefore(storage, file))
                            {
                                delete = false;
                            }
                        }
                        else
                        {
                            file.Delete();
                            OperationsLogger.Info(string.Format("Deleted local ignored file {0} because the mapped remote parent object {0} has been deleted", fsInfo.FullName, obj.RemoteObjectId));
                        }
                    }

                    if (delete)
                    {
                        try {
                            (fsInfo as IDirectoryInfo).Delete(false);
                            OperationsLogger.Info(string.Format("Deleted local folder {0} because the mapped remote folder has been deleted", fsInfo.FullName));
                        } catch (IOException) {
                            fsInfo.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, null, true);
                            return(false);
                        }
                    }
                    else
                    {
                        fsInfo.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, null, true);
                    }
                }
                else
                {
                    try {
                        (fsInfo as IDirectoryInfo).Delete(true);
                        OperationsLogger.Info(string.Format("Deleted locally ignored folder {0} because the parent mapped remote folder has been deleted", fsInfo.FullName));
                    } catch (IOException e) {
                        OperationsLogger.Info(string.Format("Deletion of locally ignored folder {0} failed", fsInfo.FullName), e);
                        return(false);
                    }
                }
            }

            return(delete);
        }