Example #1
0
File: KfsGate.cs Project: tmbx/kwm
        /// <summary>
        /// Add the missing server directories on the relative path specified in
        /// the payload specified.
        /// </summary>
        private void AddMissingServerDirectories(String path, KfsPhase1Payload payload)
        {
            String cur = "";
            UInt64 inode = 0;
            UInt64 commitID = 0;
            String rel = "";

            foreach (String c in KfsPath.SplitRelativePath(path))
            {
                if (cur != "") cur += "/";
                cur += c;

                KfsServerObject o = Share.ServerView.GetObjectByPath(cur);

                // The current directory doesn't exist. Create it.
                if (o == null)
                {
                    if (rel != "") rel += "/";
                    rel += c;
                    payload.AddCreateOp(false, inode, commitID, rel);
                }

                // The current directory is a ghost. Delete the ghost and
                // replace it by a directory.
                else if (o.IsGhost())
                {
                    Debug.Assert(rel == "");
                    DeleteGhost(o, payload);
                    rel = c;
                    payload.AddCreateOp(false, inode, commitID, rel);
                }

                // The current directory already exists in the server view.
                else
                {
                    Debug.Assert(rel == "");
                    Debug.Assert(o is KfsServerDirectory);
                    inode = o.Inode;
                    commitID = o.CommitID;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Start a new file transfer batch.
        /// </summary>
        public void StartBatch()
        {
            Debug.Assert(OrderTree.Count > 0);
            Debug.Assert(Status == UploadManagerStatus.Idle);
            Debug.Assert(TransferThread == null);
            Debug.Assert(Ticket != null);

            try
            {
                ulong emailID = 0;

                // Build the payload and the tree.
                KfsPhase1Payload p = new KfsPhase1Payload();
                SortedDictionary<UInt64, KfsUploadBatchFile> tree = new SortedDictionary<UInt64, KfsUploadBatchFile>();

                int i = -1;
                foreach (KfsFileUpload f in OrderTree.Values)
                {
                    Debug.Assert(f.Status == FileTransferStatus.Queued);
                    f.Status = FileTransferStatus.Batched;

                    // Update emailID on first file.
                    // Note: this is not a safe: uploaded files could have bad email IDs
                    // but we didn't care when this was written.
                    if (++i == 0) { emailID = f.EmailID; }

                    // Request creation.
                    if (f.UpdateCommitID == 0)
                    {
                        // Use the tracked inode if it still exists, otherwise use the
                        // last full path.
                        KfsServerObject o = Share.ServerView.GetObjectByInode(f.TrackedInode);
                        if (o == null)
                        {
                            o = Share.ServerView.Root;
                            f.TrackedInode = o.Inode;
                            f.TrackedPath = f.LastFullPath;
                        }

                        Debug.Assert(o is KfsServerDirectory);
                        Debug.Assert(f.TrackedPath != "");
                        p.AddCreateOp(true, o.Inode, o.CommitID, f.TrackedPath);
                    }

                    // Request update.
                    else
                    {
                        Debug.Assert(f.TrackedPath == "");
                        p.AddUpdateOp(f.TrackedInode, f.UpdateCommitID);
                    }

                    tree[f.OrderID] = new KfsUploadBatchFile(f.OrderID, f.UploadPath);
                }

                // Start the transfer.
                TransferThread = new KfsUploadThread(Share, Ticket, emailID, tree, p);
                TransferThread.Start();

                Status = UploadManagerStatus.Batch;
                Ticket = null;
            }

            catch (Exception ex)
            {
                Share.FatalError(ex);
            }
        }