Beispiel #1
0
        /// <summary>
        /// Writes the delete transaction file to the backend in preperation for a delete operation
        /// </summary>
        /// <param name="filename">The name of the local file with delete transaction data</param>
        public void WriteDeleteTransactionFile(string filename)
        {
            if (m_transactionFile != null)
                throw new Exception(Strings.BackendWrapper.ExistingDeleteTransactionError);

            m_transactionFile = new DeleteTransactionEntry(m_options.EncryptionModule);

            Put(m_transactionFile, filename, true);
        }
Beispiel #2
0
        /// <summary>
        /// Returns all files in the target backend
        /// </summary>
        /// <param name="filter">A value indicating if the results should be filtered according to the delete transaction</param>
        /// <returns>All files in the target backend</returns>
        public List<Library.Interface.IFileEntry> List(bool filter)
        {
            List<Library.Interface.IFileEntry> result = (List<Library.Interface.IFileEntry>)ProtectedInvoke("ListInternal");

            if (!filter)
                return result;

            m_transactionFile = null;
            List<DeleteTransactionEntry> found = new List<DeleteTransactionEntry>();

            foreach (Library.Interface.IFileEntry f in result)
            {
                DeleteTransactionEntry de = m_filenamestrategy.ParseAsDeleteTransaction(f);
                if (de != null)
                    found.Add(de);
            }

            if (found.Count > 0)
            {
                if (found.Count > 1)
                    throw new Exception(Strings.BackendWrapper.MultipleDeleteTransactionsFoundError);

                m_transactionFile = found[0];
                result.Remove(m_transactionFile.Fileentry);

                if (m_statistics != null)
                {
                    //Show the warning to the user unless we will
                    // actually delete the files later, as that would
                    // produce the warning twice
                    bool logWarning = true;

                    switch (m_options.MainAction)
                    {
                        case DuplicatiOperationMode.Backup:
                        case DuplicatiOperationMode.BackupFull:
                        case DuplicatiOperationMode.BackupIncremental:
                            logWarning = !m_options.AutoCleanup;
                            break;

                        case DuplicatiOperationMode.CleanUp:
                        case DuplicatiOperationMode.DeleteAllButN:
                        case DuplicatiOperationMode.DeleteAllButNFull:
                        case DuplicatiOperationMode.DeleteOlderThan:
                            logWarning = false;
                            break;
                    }

                    if (logWarning)
                        m_statistics.LogWarning(Strings.BackendWrapper.DeleteTransactionFileFoundWarning, null);
                }

                Dictionary<string, string> lookup = new Dictionary<string,string>();
                try
                {
                    using (Library.Utility.TempFile tf = new Utility.TempFile())
                    {
                        this.Get(m_transactionFile, null, tf, null);
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                        doc.Load(tf);

                        foreach (System.Xml.XmlNode n in doc.SelectNodes("files/file"))
                            lookup[n.InnerText] = null;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format(Strings.BackendWrapper.DeleteTransactionFileReadError, m_transactionFile.Filename, ex.Message), ex);
                }

                m_leftovers = new List<Library.Interface.IFileEntry>();

                //Filter the results reported to look as if the delete was completed,
                // and keep a list of not-yet-deleted entries
                for (int i = 0; i < result.Count; i++)
                    if (lookup.ContainsKey(result[i].Name))
                    {
                        m_leftovers.Add(result[i]);
                        result.RemoveAt(i);
                        i--;
                    }
            }

            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Removes the delete transaction file from the backend, thus completing the delete transaction
        /// </summary>
        public void RemoveDeleteTransactionFile()
        {
            if (m_transactionFile == null)
                throw new Exception(Strings.BackendWrapper.NonExistingDeleteTransactionError);

            Delete(m_transactionFile);
            m_transactionFile = null;
        }
Beispiel #4
0
        /// <summary>
        /// Deletes all files listed in the delete transaction file if it exists
        /// </summary>
        /// <param name="logAsWarnings">A value indicating if a warning message should be logged</param>
        /// <returns></returns>
        public string FinishDeleteTransaction(bool logAsWarnings)
        {
            StringBuilder sb = new StringBuilder();

            if (m_transactionFile != null)
            {
                if (logAsWarnings)
                    m_statistics.LogWarning(string.Format(Strings.BackendWrapper.CompletingDeleteTransactionWarning, m_leftovers.Count), null);
                sb.AppendLine(string.Format(Strings.BackendWrapper.CompletingDeleteTransactionWarning, m_leftovers.Count));

                foreach (Library.Interface.IFileEntry s in m_leftovers)
                {
                    sb.AppendLine(string.Format(Strings.BackendWrapper.DeletingTransactionLeftoverFile, s.Name));

                    BackupEntryBase be = m_filenamestrategy.ParseFilename(s);
                    if (m_options.Force)
                        this.Delete(be ?? new SignatureEntry(s.Name, s, DateTime.Now, true, "", "", "", 0));
                }

                sb.AppendLine(string.Format(Strings.BackendWrapper.DeletingTransactionLeftoverFile, m_transactionFile.Filename));

                if (m_options.Force)
                    this.Delete(m_transactionFile);

                m_transactionFile = null;

                sb.AppendLine(Strings.BackendWrapper.CompletedDeleteTransaction);

                if (!m_options.Force)
                    sb.AppendLine(Strings.BackendWrapper.FilesNotForceRemovedMessage);
            }

            return sb.ToString();
        }