/// <summary> /// Remove the specified upload. /// </summary> private void RemoveUpload(KfsFileUpload f) { OrderTree.Remove(f.OrderID); if (DoneTree.ContainsKey(f.OrderID)) DoneTree.Remove(f.OrderID); Share.MetaDataManager.RemoveUpload(f.OrderID); Share.UnregisterFileTransfer(f); }
/// <summary> /// Queue the upload of the file specified. The method checks if the /// file is already being transferred. If so, null is returned, otherwise /// the file is copied in the upload directory and the reference to the /// file upload is returned. /// </summary> public KfsFileUpload QueueUpload(String path, ulong emailID) { // If the file is already being transferred, abort. if (Share.IsTransferringFile(path)) return null; String fullPath = Share.MakeAbsolute(path); UInt64 trackedInode; String trackedPath; UInt64 updateCommitID; // Locate the file, if it exists. KfsServerFile f = Share.ServerView.GetObjectByPath(path) as KfsServerFile; // The file exists and it is not a ghost. Queue as update. if (f != null && !f.IsGhost()) { trackedInode = f.Inode; trackedPath = ""; updateCommitID = f.CommitID; } // The file does not exist or it is ghost. Queue as create. The caller // will get rid of the ghost if it exists. else { GetTrackingInodeAndPath(path, out trackedInode, out trackedPath); updateCommitID = 0; } // Link or copy the file in the upload directory. UInt64 orderID = Share.TransferOrderID++; String uploadPath = GetTemporaryPath(orderID); File.Delete(uploadPath); try { if (!Syscalls.CreateHardLink(uploadPath, fullPath, IntPtr.Zero)) throw new Exception(Syscalls.GetLastErrorStringMessage()); } catch (Exception ex) { Logging.Log(1, "Could not create hard link: " + ex.Message); Base.SafeCopy(fullPath, uploadPath, true); } // Get the file size. UInt64 size = KfsPath.GetFileSize(uploadPath); // Queue the upload. KfsFileUpload u = new KfsFileUpload(Share, orderID, trackedInode, trackedPath, path, uploadPath, size, updateCommitID, emailID); OrderTree[u.OrderID] = u; Share.RegisterFileTransfer(u); return u; }
/// <summary> /// Add the file upload to the list of errors, unless 'reason' is null. /// </summary> public void ReportError(String reason, KfsFileUpload f) { if (reason != null) { f.Error = new KfsTransferError(TransferErrorType.Upload, f, reason); Share.OnTransferError(f.Error); } }
/// <summary> /// Queue the upload of the file specified. The method checks if the /// file is already being transferred. If so, null is returned, otherwise /// the file is copied in the upload directory and the reference to the /// file upload is returned. /// </summary> public KfsFileUpload QueueUpload(String path) { // If the file is already being transferred, abort. if (Share.IsTransferringFile(path)) return null; String fullPath = Share.MakeAbsolute(path); UInt64 trackedInode; String trackedPath; UInt64 updateCommitID; // Locate the file, if it exists. KfsServerFile f = Share.ServerView.GetObjectByPath(path) as KfsServerFile; // The file exists and it is not a ghost. Queue as update. if (f != null && !f.IsGhost()) { trackedInode = f.Inode; trackedPath = ""; updateCommitID = f.CommitID; } // The file does not exist or it is ghost. Queue as create. The caller // will get rid of the ghost if it exists. else { GetTrackingInodeAndPath(path, out trackedInode, out trackedPath); updateCommitID = 0; } // Copy the file in the upload directory. UInt64 orderID = Share.TransferOrderID++; String uploadPath = GetTemporaryPath(orderID); if (File.Exists(uploadPath)) File.SetAttributes(uploadPath, FileAttributes.Normal); if (new FileInfo(fullPath).Length < 10 * 1024 * 1024) Base.SafeCopy(fullPath, uploadPath, true); else if (!Misc.CopyFile(fullPath, uploadPath, false, true, false, true, true)) throw new Exception("Unable to copy " + path); // Compute the hash and the size. byte[] hash; UInt64 size; KfsHash.GetHashAndSize(fullPath, out hash, out size); // Queue the upload. KfsFileUpload u = new KfsFileUpload(Share, orderID, trackedInode, trackedPath, path, uploadPath, size, hash, updateCommitID); OrderTree[u.OrderID] = u; Share.RegisterFileTransfer(u); return u; }