Просмотр исходного кода

Optimized share API remove share need to call to 3 seperate function design issue

Toby Chui 3 лет назад
Родитель
Сommit
3f20309193
1 измененных файлов с 7 добавлено и 10 удалено
  1. 7 10
      mod/share/share.go

+ 7 - 10
mod/share/share.go

@@ -936,9 +936,12 @@ func validateShareModes(mode string) (bool, string, []string) {
 }
 
 func (s *Manager) RemoveShareByRealpath(rpath string) error {
-	_, ok := s.fileToUrlMap.Load(rpath)
+	so, ok := s.fileToUrlMap.Load(rpath)
 	if ok {
+		shareUUID := so.(*ShareOption).UUID
+		s.urlToFileMap.Delete(shareUUID)
 		s.fileToUrlMap.Delete(rpath)
+		s.options.Database.Delete("share", shareUUID)
 	} else {
 		return errors.New("Share with given realpath not exists")
 	}
@@ -946,9 +949,11 @@ func (s *Manager) RemoveShareByRealpath(rpath string) error {
 }
 
 func (s *Manager) RemoveShareByUUID(uuid string) error {
-	_, ok := s.urlToFileMap.Load(uuid)
+	so, ok := s.urlToFileMap.Load(uuid)
 	if ok {
+		s.fileToUrlMap.Delete(so.(*ShareOption).FileRealPath)
 		s.urlToFileMap.Delete(uuid)
+		s.options.Database.Delete("share", uuid)
 	} else {
 		return errors.New("Share with given uuid not exists")
 	}
@@ -962,15 +967,7 @@ func (s *Manager) ValidateAndClearShares() {
 		thisRealPath := k.(string)
 		if !fileExists(thisRealPath) {
 			//This share source file don't exists anymore. Remove it
-			thisFileShareOption := v.(*ShareOption)
-
-			//Delete this task from both sync map
 			s.RemoveShareByRealpath(thisRealPath)
-			s.RemoveShareByUUID(thisFileShareOption.UUID)
-
-			//Remove share from database
-			s.options.Database.Delete("share", thisFileShareOption.UUID)
-
 			log.Println("*Share* Removing share to file: " + thisRealPath + " as it no longer exists")
 		}
 		return true