6767use OCP \Files \Mount \IMountPoint ;
6868use OCP \Files \NotFoundException ;
6969use OCP \Files \ReservedWordException ;
70+ use OCP \IL10N ;
7071use OCP \IUser ;
72+ use OCP \L10N \IFactory ;
7173use OCP \Lock \ILockingProvider ;
7274use OCP \Lock \LockedException ;
7375use OCP \Server ;
@@ -98,6 +100,7 @@ class View {
98100 private bool $ updaterEnabled = true ;
99101 private UserManager $ userManager ;
100102 private LoggerInterface $ logger ;
103+ private IL10N $ l10n ;
101104
102105 /**
103106 * @throws \Exception If $root contains an invalid path
@@ -112,6 +115,7 @@ public function __construct(string $root = '') {
112115 $ this ->lockingEnabled = !($ this ->lockingProvider instanceof \OC \Lock \NoopLockingProvider);
113116 $ this ->userManager = \OC ::$ server ->getUserManager ();
114117 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
118+ $ this ->l10n = \OC ::$ server ->get (IFactory::class)->get ('files ' );
115119 }
116120
117121 /**
@@ -874,30 +878,51 @@ public function rename($source, $target) {
874878 return $ result ;
875879 }
876880
881+ /**
882+ * @throws ForbiddenException
883+ */
877884 private function validateMountMove (array $ mounts , IMountPoint $ sourceMount , IMountPoint $ targetMount , bool $ targetIsShared ): void {
878- $ targetType = 'storage ' ;
879- if ($ targetMount instanceof SharedMount) {
880- $ targetType = 'share ' ;
885+ $ targetPath = $ this ->getRelativePath ($ targetMount ->getMountPoint ());
886+ if ($ targetPath ) {
887+ $ targetPath = trim ($ targetPath , '/ ' );
888+ } else {
889+ $ targetPath = $ targetMount ->getMountPoint ();
881890 }
882- $ targetPath = rtrim ($ targetMount ->getMountPoint (), '/ ' );
883891
884892 foreach ($ mounts as $ mount ) {
885- $ sourcePath = rtrim ($ mount ->getMountPoint (), '/ ' );
886- $ sourceType = 'storage ' ;
887- if ($ mount instanceof SharedMount) {
888- $ sourceType = 'share ' ;
893+ $ sourcePath = $ this ->getRelativePath ($ mount ->getMountPoint ());
894+ if ($ sourcePath ) {
895+ $ sourcePath = trim ($ sourcePath , '/ ' );
896+ } else {
897+ $ sourcePath = $ mount ->getMountPoint ();
889898 }
890899
891900 if (!$ mount instanceof MoveableMount) {
892- throw new ForbiddenException (" Storage { $ sourcePath } cannot be moved " , false );
901+ throw new ForbiddenException ($ this -> l10n -> t ( ' Storage %s cannot be moved ' , [ $ sourcePath ]) , false );
893902 }
894903
895904 if ($ targetIsShared ) {
896- throw new ForbiddenException ("Moving a $ sourceType ( $ sourcePath) into shared folder is not allowed " , false );
905+ if ($ sourceMount instanceof SharedMount) {
906+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into a shared folder is not allowed ' , [$ sourcePath ]), false );
907+ } else {
908+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into a shared folder is not allowed ' , [$ sourcePath ]), false );
909+ }
897910 }
898911
899912 if ($ sourceMount !== $ targetMount ) {
900- throw new ForbiddenException ("Moving a $ sourceType ( $ sourcePath) into another $ targetType ( $ targetPath) is not allowed " , false );
913+ if ($ sourceMount instanceof SharedMount) {
914+ if ($ targetMount instanceof SharedMount) {
915+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into another share (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
916+ } else {
917+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a share (%s) into another storage (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
918+ }
919+ } else {
920+ if ($ targetMount instanceof SharedMount) {
921+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into a share (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
922+ } else {
923+ throw new ForbiddenException ($ this ->l10n ->t ('Moving a storage (%s) into another storage (%s) is not allowed ' , [$ sourcePath , $ targetPath ]), false );
924+ }
925+ }
901926 }
902927 }
903928 }
0 commit comments