/// <summary> /// Rename the file that is in the way of the node with the name conflict. /// </summary> /// <param name="newName">The new name of the file.</param> public void RenameConflictingFile(string newName) { if (!SyncFile.IsNameValid(newName)) { throw new MalformedException(newName); } // Now get the conflicting node. Node cfn = collection.GetNodeByID(node.Properties.GetSingleProperty(ConflictLinkProperty).Value.ToString()); FileNode fn = cfn as FileNode; if (fn != null) { // Now rename the file and the node. string parentPath = Path.GetDirectoryName(fn.GetFullPath(collection)); string tmpName = Path.Combine(parentPath, TempFilePrefix + fn.ID); string newFName = Path.Combine(parentPath, newName); File.Move(fn.GetFullPath(collection), tmpName); File.Move(tmpName, newFName); string relativePath = fn.GetRelativePath(); relativePath = relativePath.Remove(relativePath.Length - fn.Name.Length, fn.Name.Length) + newName; fn.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath)); fn.Name = newName; fn = RemoveNameConflict(collection, fn) as FileNode; collection.Commit(fn); } else { DirNode dn = cfn as DirNode; if (dn != null) { new Conflict(collection, dn).Resolve(newName); } } }
/// <summary> /// Checks for a name conflict. /// </summary> /// <returns>True if conflict.</returns> protected bool CheckForNameConflict() { if (!NameConflict) { // Look up the FsPath property (StoreFileNodes don't have this property set). Property property = node.Properties.GetSingleProperty(PropertyTags.FileSystemPath); if (property != null) { string path = property.Value.ToString(); ICSList nodeList; nodeList = collection.Search(PropertyTags.FileSystemPath, path, SearchOp.Equal); foreach (ShallowNode sn in nodeList) { FileNode localFileNode = new FileNode(collection.GetNodeByID(sn.ID)); // Set name conflict true if both file doesn't match if (sn.ID != node.ID && String.Compare(new FileNode(node).GetRelativePath(), localFileNode.GetRelativePath(), false) != 0) { conflictingNode = collection.GetNodeByID(sn.ID); nameConflict = true; break; } } // Now make sure we don't have any illegal characters. if (!IsNameValid(path)) { nameConflict = true; } if (nameConflict) { node = Conflict.CreateNameConflict(collection, node) as BaseFileNode; file = Conflict.GetFileConflictPath(collection, node); if (conflictingNode != null) { string cnPath; FileNode tmpFn = conflictingNode as FileNode; DirNode tmpDn = conflictingNode as DirNode; if (tmpFn != null) { cnPath = tmpFn.GetFullPath(collection); } else { cnPath = tmpDn.GetFullPath(collection); } conflictingNode = Conflict.CreateNameConflict(collection, conflictingNode, cnPath); Conflict.LinkConflictingNodes(conflictingNode, node); } } } } return(nameConflict); }
/// <summary> /// Constructor /// </summary> /// <param name="ifolderID">The ID of the iFolder.</param> /// <param name="entryID">The ID of the Entry.</param> /// <param name="accessID">The Access ID.</param> public iFolderFile(string ifolderID, string entryID, string accessID) { Store store = Store.GetStore(); collection = store.GetCollectionByID(ifolderID); if (collection == null) { throw new iFolderDoesNotExistException(ifolderID); } // impersonate this.accessID = accessID; iFolder.Impersonate(collection, accessID); // member member = collection.GetMemberByID(accessID); // does member exist? if (member == null) { throw new MemberDoesNotExistException(accessID); } // node Node n = collection.GetNodeByID(entryID); // does the node exist? if (n == null) { throw new EntryDoesNotExistException(entryID); } // is the node a file if (!n.IsBaseType(NodeTypes.FileNodeType)) { throw new FileDoesNotExistException(entryID); } // log log = new SimiasAccessLogger(member.Name, collection.ID); // node node = (FileNode)n; id = String.Format("{0}:{1}", collection.ID, n.ID); path = node.GetFullPath(collection); updating = false; }
//--------------------------------------------------------------------------- /// <summary> /// resolve update conflict and commit /// </summary> public void Resolve(bool localChangesWin) { if (conflictNode == null) { return; } if (localChangesWin) { string ucp = UpdateConflictPath; if (ucp != null) { File.Delete(ucp); } node = collection.ResolveCollision(node, conflictNode.LocalIncarnation, true); collection.Commit(node); Log.log.Debug("Local changes win in conflict for {0} node {1}", node.Type, node.Name); return; } // conflict node wins // we may be resolving an update conflict on a node that has a naming conflict string path = NonconflictedPath, fncpath = null; FileInfo fInfo = null; Log.log.Debug("Resolve conflict file ServerChangesWin"); if (path != null) { try { FileNode fileNode = (FileNode)this.node; string fileName = fileNode.GetFullPath(collection); Log.log.Debug("Resolve conflict file name :{0}", fileName); FileNode CNode = (FileNode)this.conflictNode; string Conflictname = CNode.GetFullPath(collection); Log.log.Debug("Resolve conflict Conflict file name :{0}", Conflictname); Log.log.Debug("Resolve conflict Delete File :{0}", fileName); //Delete this client's(local) file File.Delete(fileName); Log.log.Debug("Resolve conflict UpdateConflictPath :{0}", UpdateConflictPath); if (String.Compare(fileName, Conflictname, false) != 0) { Log.log.Debug("Resolve conflict file nameand conflict file name match not found between '{0}'....to.....'{1}'", fileName, Conflictname); Log.log.Debug("Resolve conflict move from '{0}' ....to....'{1}'", UpdateConflictPath, Conflictname); //Move the server file //use the server name File.Move(UpdateConflictPath, Conflictname); fInfo = new FileInfo(Conflictname); } else { Log.log.Debug("Resolve conflict file nameand conflict file name match found between '{0}'....to.....'{1}'", fileName, fileName); Log.log.Debug("Resolve conflict move from '{0}' ....to....'{1}'", UpdateConflictPath, fileName); //Move the server file use the lcoal name File.Move(UpdateConflictPath, fileName); fInfo = new FileInfo(fileName); } Log.log.Debug("Resolve conflict server changed has won"); } catch (Exception ne) { Log.log.Debug("Could not move update conflict file to {0}: {1}", path, ne.Message); fncpath = FileNameConflictPath; File.Delete(fncpath); File.Move(UpdateConflictPath, fncpath); } } node = collection.ResolveCollision(node, conflictNode.LocalIncarnation, false); if (fncpath != null) { Log.log.Debug("Resolve conflict(we may be resolving an update conflict on a node that has a naming conflict) fncpath: {0}", fncpath); node = CreateNameConflict(collection, node, path); } if (fInfo != null) { BaseFileNode bfn = node as BaseFileNode; if (bfn != null) { fInfo.CreationTime = bfn.CreationTime; fInfo.LastWriteTime = bfn.LastWriteTime; } } conflictNode = null; collection.Commit(node); Log.log.Debug("Master update wins in conflict for {0} node {1}", node.Type, node.Name); }
/// <summary> /// Delete An iFolder Entry /// </summary> /// <param name="ifolderID">The ID of the iFolder.</param> /// <param name="entryID">The ID of the Entry.</param> /// <param name="accessID">The Access User ID.</param> public static void DeleteEntry(string ifolderID, string entryID, string accessID) { Store store = Store.GetStore(); Collection c = store.GetCollectionByID(ifolderID); if (c == null) { throw new iFolderDoesNotExistException(ifolderID); } // impersonate iFolder.Impersonate(c, accessID); Node n = c.GetNodeByID(entryID); if (n == null) { throw new EntryDoesNotExistException(entryID); } // directory if (n.IsBaseType(NodeTypes.DirNodeType)) { DirNode dn = (DirNode)n; if (dn.IsRoot) { throw new DirectoryEntryRequiredException(entryID); } string path = dn.GetFullPath(c); if (Directory.Exists(path)) { Directory.Delete(path, true); } // delete recursivley c.Commit(c.Delete(dn, PropertyTags.Parent)); } // file else if (n.IsBaseType(NodeTypes.FileNodeType)) { FileNode fn = (FileNode)n; string path = fn.GetFullPath(c); if (File.Exists(path)) { File.Delete(path); } c.Commit(c.Delete(fn)); } // not an entry else { throw new EntryDoesNotExistException(entryID); } }
/// <summary> /// process the http request /// </summary> /// <param name="context">http context</param> public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; response.StatusCode = (int)HttpStatusCode.BadRequest; try { // Make sure that there is a session. if (context.Session != null) { //HttpService service = Session[ serviceTag ]; response.Cache.SetCacheability(HttpCacheability.NoCache); string method = request.HttpMethod.ToLower(); log.Debug("Simias.HttpFile.Handler.ProcessRequest called"); log.Debug(" method: " + method); //SyncMethod method = (SyncMethod)Enum.Parse(typeof(SyncMethod), Request.Headers.Get(SyncHeaders.Method), true); if (method == "get") { // Must a query string which contains the domainid and the // filenodeid for the file caller is attempting to download. if (request.QueryString.Count > 0) { Collection collection; Domain domain; FileNode fileNode; Node node; Store store = Store.GetStore(); string domainID = request.QueryString["did"]; if (domainID == null) { domainID = store.DefaultDomain; } string fileID = request.QueryString["fid"]; if (fileID != null) { log.Debug(" domainID: " + domainID); log.Debug(" fileID: " + fileID); domain = Store.GetStore().GetDomain(domainID); node = domain.GetNodeByID(fileID); if (node != null) { Property cid = node.Properties.GetSingleProperty("CollectionId"); collection = store.GetCollectionByID(cid.Value as string); fileNode = new FileNode(node); string fullPath = fileNode.GetFullPath(collection); string fileName = fileNode.GetFileName(); log.Debug(" nodename: " + fileNode.Name); log.Debug(" filename: " + fileName); log.Debug(" fullpath: " + fullPath); response.StatusCode = (int)HttpStatusCode.OK; Property lastModified = node.Properties.GetSingleProperty("LastModified"); if (lastModified != null) { DateTime dt = (DateTime)lastModified.Value; response.AddHeader( "Last-Modified", Util.GetRfc822Date((DateTime)lastModified.Value)); } response.AddHeader( "Content-length", fileNode.Length.ToString()); response.ContentType = Simias.HttpFile.Response.GetMimeType(fileName).ToLower(); if (response.ContentType.Equals("text/plain")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else if (response.ContentType.Equals("text/xml")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else if (response.ContentType.StartsWith("image")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else { response.AddHeader( "Content-Disposition", "attachment; filename=\"" + fileName + "\""); } response.TransmitFile(fullPath); /* * response. * FileStream stream = * File.Open( * fullPath, * System.IO.FileMode.Open, * System.IO.FileAccess.Read, * System.IO.FileShare.Read ); */ } } } } } } catch (Exception ex) { log.Error(ex.Message); log.Error(ex.StackTrace); response.StatusCode = (int)HttpStatusCode.InternalServerError; } finally { response.End(); } }
/// <summary> /// Initialize the Request /// </summary> /// <param name="context">The HttpContext object.</param> protected void Initialize(HttpContext context) { // query ifolderID = context.Request.QueryString["iFolder"]; entryID = context.Request.QueryString["Entry"]; entryPath = context.Request.QueryString["Path"]; string ppath = entryPath; string [] ConversionTable = { "&", "amp@:quot" }; if (ppath != null) { for (int index = 0; index < ConversionTable.Length; index += 2) { ppath = ppath.Replace(ConversionTable[index + 1], ConversionTable[index]); } } entryPath = ppath; // authentication accessID = context.User.Identity.Name; if ((accessID == null) || (accessID.Length == 0)) { throw new AuthenticationException(); } // store store = Store.GetStore(); // collection collection = store.GetCollectionByID(ifolderID); if (collection == null) { throw new iFolderDoesNotExistException(ifolderID); } // member member = collection.GetMemberByID(accessID); // does member exist? if (member == null && Simias.Service.Manager.LdapServiceEnabled == true) { Domain domain = store.GetDomain(store.DefaultDomain); string[] IDs = domain.GetMemberFamilyList(accessID); foreach (string id in IDs) { member = collection.GetMemberByID(id); if (member != null) { break; } } } if (member == null) { throw new MemberDoesNotExistException(accessID); } // impersonate iFolder.Impersonate(collection, accessID); // log log = new SimiasAccessLogger(member.Name, collection.ID); // node Node n = null; // use the path if ((entryPath != null) && (entryPath.Length != 0)) { n = iFolderEntry.GetEntryByPath(collection, entryPath); } // use the id if ((entryID != null) && (entryID.Length != 0)) { n = collection.GetNodeByID(entryID); } // check node if (n != null) { // is the node a file if (!n.IsBaseType(NodeTypes.FileNodeType)) { throw new FileDoesNotExistException(entryID); } // file node = (FileNode)n; filename = node.GetFileName(); filePath = node.GetFullPath(collection); } }