File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -697,13 +697,25 @@ public function createShare(IShare $share) {
697
697
$ this ->linkCreateChecks ($ share );
698
698
$ this ->setLinkParent ($ share );
699
699
700
- // For now ignore a set token.
701
- $ share ->setToken (
702
- $ this ->secureRandom ->generate (
700
+ for ($ i = 0 ; $ i <= 3 ; $ i ++) {
701
+ $ token = $ this ->secureRandom ->generate (
703
702
\OC \Share \Constants::TOKEN_LENGTH ,
704
703
\OCP \Security \ISecureRandom::CHAR_HUMAN_READABLE
705
- )
706
- );
704
+ );
705
+
706
+ try {
707
+ $ this ->getShareByToken ($ token );
708
+ } catch (\OCP \Share \Exceptions \ShareNotFound $ e ) {
709
+ // Set the unique token
710
+ $ share ->setToken ($ token );
711
+ break ;
712
+ }
713
+
714
+ // Abort after 3 failed attempts
715
+ if ($ i >= 3 ) {
716
+ throw new \Exception ('Unable to generate a unique share token after 3 attempts. ' );
717
+ }
718
+ }
707
719
708
720
// Verify the expiration date
709
721
$ share = $ this ->validateExpirationDateLink ($ share );
You can’t perform that action at this time.
0 commit comments