Exemplo n.º 1
0
        /* Entry point for un-sharing file with a user*/
        public void unShareFileWithUser(string clientId, string filename, string sharedWithUser)
        {
            Logger.Debug("Un Sharing file " + filename + " owned by user " + clientId + " with user " + sharedWithUser);
            UserFileSystem fs          = getUserFSFromMapSynchronized(clientId);
            bool           filepresent = fs.isFilePresentSynchronized(filename);

            fs.removeSharedUserFromFileSynchronized(filename, sharedWithUser);

            if (!filepresent)
            {
                throw new FileNotFoundException("File not present in memory for client : " + filename + " for client : " + clientId);
            }

            UserFileSystem sharedFS = getUserFSFromMapSynchronized(sharedWithUser);
            bool           deleted  = sharedFS.deleteSharedFileSynchronized(new SharedFile(clientId, filename));

            if (!deleted)
            {
                Logger.Debug("Shared file was not present , skipping deletion");
            }
        }
Exemplo n.º 2
0
        /* Entry point for delete file*/
        public bool deleteFileSynchronized(string clientid, string filename)
        {
            Logger.Debug("Deleting file : " + filename + " owned by : " + clientid);

            //1) Remove the file from the file system of the client
            //2) Remove the file from the file system of all shared clients

            UserFileSystem fs = getUserFSFromMapSynchronized(clientid);

            if (fs == null)
            {
                throw new UserNotLoadedInMemoryException("User not loaded in memory :" + clientid);
            }

            bool delete = fs.deleteFileSynchronized(filename);

            List <string> sharedClients = fs.getFileMetaDataCloneSynchronized(filename).sharedwithclients;

            foreach (string sharedclient in sharedClients)
            {
                UserFileSystem fsShared = getUserFSFromMapSynchronized(sharedclient);

                if (fsShared != null)
                {
                    Logger.Debug("Removing file : " + filename + " from shared client fs : " + sharedclient);
                    fsShared.deleteSharedFileSynchronized(new SharedFile(clientid, filename));
                }
                else
                {
                    Logger.Warn("The shared user file system is missing from the memory, see what happened");
                }
            }


            return(delete);
        }