2828use OCP \Files \Mount \IMountPoint ;
2929use OCP \Files \NotFoundException ;
3030use OCP \Files \ReservedWordException ;
31+ use OCP \IL10N ;
3132use OCP \IUser ;
3233use OCP \IUserManager ;
34+ use OCP \L10N \IFactory ;
3335use OCP \Lock \ILockingProvider ;
3436use OCP \Lock \LockedException ;
3537use OCP \Server ;
@@ -60,6 +62,7 @@ class View {
6062 private bool $ updaterEnabled = true ;
6163 private UserManager $ userManager ;
6264 private LoggerInterface $ logger ;
65+ private IL10N $ l10n ;
6366
6467 /**
6568 * @throws \Exception If $root contains an invalid path
@@ -74,6 +77,7 @@ public function __construct(string $root = '') {
7477 $ this ->lockingEnabled = !($ this ->lockingProvider instanceof \OC \Lock \NoopLockingProvider);
7578 $ this ->userManager = \OC ::$ server ->getUserManager ();
7679 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
80+ $ this ->l10n = \OC ::$ server ->get (IFactory::class)->get ('files ' );
7781 }
7882
7983 /**
@@ -846,30 +850,51 @@ public function rename($source, $target) {
846850 return $ result ;
847851 }
848852
853+ /**
854+ * @throws ForbiddenException
855+ */
849856 private function validateMountMove (array $ mounts , IMountPoint $ sourceMount , IMountPoint $ targetMount , bool $ targetIsShared ): void {
850- $ targetType = 'storage ' ;
851- if ($ targetMount instanceof SharedMount) {
852- $ targetType = 'share ' ;
857+ $ targetPath = $ this ->getRelativePath ($ targetMount ->getMountPoint ());
858+ if ($ targetPath ) {
859+ $ targetPath = trim ($ targetPath , '/ ' );
860+ } else {
861+ $ targetPath = $ targetMount ->getMountPoint ();
853862 }
854- $ targetPath = rtrim ($ targetMount ->getMountPoint (), '/ ' );
855863
856864 foreach ($ mounts as $ mount ) {
857- $ sourcePath = rtrim ($ mount ->getMountPoint (), '/ ' );
858- $ sourceType = 'storage ' ;
859- if ($ mount instanceof SharedMount) {
860- $ sourceType = 'share ' ;
865+ $ sourcePath = $ this ->getRelativePath ($ mount ->getMountPoint ());
866+ if ($ sourcePath ) {
867+ $ sourcePath = trim ($ sourcePath , '/ ' );
868+ } else {
869+ $ sourcePath = $ mount ->getMountPoint ();
861870 }
862871
863872 if (!$ mount instanceof MoveableMount) {
864- throw new ForbiddenException (" Storage { $ sourcePath } cannot be moved " , false );
873+ throw new ForbiddenException ($ this -> l10n -> t ( ' Storage %s cannot be moved ' , [ $ sourcePath ]) , false );
865874 }
866875
867876 if ($ targetIsShared ) {
868- throw new ForbiddenException ("Moving a $ sourceType ( $ sourcePath) into shared folder is not allowed " , false );
877+ if ($ sourceMount instanceof SharedMount) {
878+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into a shared folder is not allowed ' , [$ sourcePath ]), false );
879+ } else {
880+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into a shared folder is not allowed ' , [$ sourcePath ]), false );
881+ }
869882 }
870883
871884 if ($ sourceMount !== $ targetMount ) {
872- throw new ForbiddenException ("Moving a $ sourceType ( $ sourcePath) into another $ targetType ( $ targetPath) is not allowed " , false );
885+ if ($ sourceMount instanceof SharedMount) {
886+ if ($ targetMount instanceof SharedMount) {
887+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into another share (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
888+ } else {
889+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into another storage (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
890+ }
891+ } else {
892+ if ($ targetMount instanceof SharedMount) {
893+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into a share (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
894+ } else {
895+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into another storage (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
896+ }
897+ }
873898 }
874899 }
875900 }
0 commit comments