File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -689,13 +689,25 @@ public function createShare(IShare $share) {
689689 $ this ->linkCreateChecks ($ share );
690690 $ this ->setLinkParent ($ share );
691691
692- // For now ignore a set token.
693- $ share ->setToken (
694- $ this ->secureRandom ->generate (
692+ for ($ i = 0 ; $ i <= 3 ; $ i ++) {
693+ $ token = $ this ->secureRandom ->generate (
695694 \OC \Share \Constants::TOKEN_LENGTH ,
696695 \OCP \Security \ISecureRandom::CHAR_HUMAN_READABLE
697- )
698- );
696+ );
697+
698+ try {
699+ $ this ->getShareByToken ($ token );
700+ } catch (\OCP \Share \Exceptions \ShareNotFound $ e ) {
701+ // Set the unique token
702+ $ share ->setToken ($ token );
703+ break ;
704+ }
705+
706+ // Abort after 3 failed attempts
707+ if ($ i >= 3 ) {
708+ throw new \Exception ('Unable to generate a unique share token after 3 attempts. ' );
709+ }
710+ }
699711
700712 // Verify the expiration date
701713 $ share = $ this ->validateExpirationDateLink ($ share );
You can’t perform that action at this time.
0 commit comments