@@ -747,65 +747,69 @@ public function deleteAll($directory) {
747747 /**
748748 * Rename/move a file or folder from the source path to target path.
749749 *
750- * @param string $path1 source path
751- * @param string $path2 target path
750+ * @param string $source source path
751+ * @param string $target target path
752752 *
753753 * @return bool|mixed
754754 * @throws LockedException
755755 */
756- public function rename ($ path1 , $ path2 ) {
757- $ absolutePath1 = Filesystem::normalizePath ($ this ->getAbsolutePath ($ path1 ));
758- $ absolutePath2 = Filesystem::normalizePath ($ this ->getAbsolutePath ($ path2 ));
756+ public function rename ($ source , $ target ) {
757+ $ absolutePath1 = Filesystem::normalizePath ($ this ->getAbsolutePath ($ source ));
758+ $ absolutePath2 = Filesystem::normalizePath ($ this ->getAbsolutePath ($ target ));
759759 $ result = false ;
760760 if (
761- Filesystem::isValidPath ($ path2 )
762- and Filesystem::isValidPath ($ path1 )
763- and !Filesystem::isFileBlacklisted ($ path2 )
761+ Filesystem::isValidPath ($ target )
762+ && Filesystem::isValidPath ($ source )
763+ && !Filesystem::isFileBlacklisted ($ target )
764764 ) {
765- $ path1 = $ this ->getRelativePath ($ absolutePath1 );
766- $ path2 = $ this ->getRelativePath ($ absolutePath2 );
767- $ exists = $ this ->file_exists ($ path2 );
765+ $ source = $ this ->getRelativePath ($ absolutePath1 );
766+ $ target = $ this ->getRelativePath ($ absolutePath2 );
767+ $ exists = $ this ->file_exists ($ target );
768768
769- if ($ path1 == null or $ path2 == null ) {
769+ if ($ source == null || $ target == null ) {
770770 return false ;
771771 }
772772
773- $ this ->lockFile ($ path1 , ILockingProvider::LOCK_SHARED , true );
773+ $ this ->lockFile ($ source , ILockingProvider::LOCK_SHARED , true );
774774 try {
775- $ this ->lockFile ($ path2 , ILockingProvider::LOCK_SHARED , true );
775+ $ this ->lockFile ($ target , ILockingProvider::LOCK_SHARED , true );
776776
777777 $ run = true ;
778- if ($ this ->shouldEmitHooks ($ path1 ) && (Cache \Scanner::isPartialFile ($ path1 ) && !Cache \Scanner::isPartialFile ($ path2 ))) {
778+ if ($ this ->shouldEmitHooks ($ source ) && (Cache \Scanner::isPartialFile ($ source ) && !Cache \Scanner::isPartialFile ($ target ))) {
779779 // if it was a rename from a part file to a regular file it was a write and not a rename operation
780- $ this ->emit_file_hooks_pre ($ exists , $ path2 , $ run );
781- } elseif ($ this ->shouldEmitHooks ($ path1 )) {
782- \OC_Hook::emit (
783- Filesystem::CLASSNAME , Filesystem::signal_rename,
784- [
785- Filesystem::signal_param_oldpath => $ this ->getHookPath ($ path1 ),
786- Filesystem::signal_param_newpath => $ this ->getHookPath ($ path2 ),
787- Filesystem::signal_param_run => &$ run
788- ]
789- );
780+ $ this ->emit_file_hooks_pre ($ exists , $ target , $ run );
781+ } elseif ($ this ->shouldEmitHooks ($ source )) {
782+ $ sourcePath = $ this ->getHookPath ($ source );
783+ $ targetPath = $ this ->getHookPath ($ target );
784+ if ($ sourcePath !== null && $ targetPath !== null ) {
785+ \OC_Hook::emit (
786+ Filesystem::CLASSNAME , Filesystem::signal_rename,
787+ [
788+ Filesystem::signal_param_oldpath => $ sourcePath ,
789+ Filesystem::signal_param_newpath => $ targetPath ,
790+ Filesystem::signal_param_run => &$ run
791+ ]
792+ );
793+ }
790794 }
791795 if ($ run ) {
792- $ this ->verifyPath (dirname ($ path2 ), basename ($ path2 ));
796+ $ this ->verifyPath (dirname ($ target ), basename ($ target ));
793797
794798 $ manager = Filesystem::getMountManager ();
795- $ mount1 = $ this ->getMount ($ path1 );
796- $ mount2 = $ this ->getMount ($ path2 );
799+ $ mount1 = $ this ->getMount ($ source );
800+ $ mount2 = $ this ->getMount ($ target );
797801 $ storage1 = $ mount1 ->getStorage ();
798802 $ storage2 = $ mount2 ->getStorage ();
799803 $ internalPath1 = $ mount1 ->getInternalPath ($ absolutePath1 );
800804 $ internalPath2 = $ mount2 ->getInternalPath ($ absolutePath2 );
801805
802- $ this ->changeLock ($ path1 , ILockingProvider::LOCK_EXCLUSIVE , true );
806+ $ this ->changeLock ($ source , ILockingProvider::LOCK_EXCLUSIVE , true );
803807 try {
804- $ this ->changeLock ($ path2 , ILockingProvider::LOCK_EXCLUSIVE , true );
808+ $ this ->changeLock ($ target , ILockingProvider::LOCK_EXCLUSIVE , true );
805809
806810 if ($ internalPath1 === '' ) {
807811 if ($ mount1 instanceof MoveableMount) {
808- $ sourceParentMount = $ this ->getMount (dirname ($ path1 ));
812+ $ sourceParentMount = $ this ->getMount (dirname ($ source ));
809813 if ($ sourceParentMount === $ mount2 && $ this ->targetIsNotShared ($ storage2 , $ internalPath2 )) {
810814 /**
811815 * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
@@ -819,19 +823,19 @@ public function rename($path1, $path2) {
819823 } else {
820824 $ result = false ;
821825 }
822- // moving a file/folder within the same mount point
826+ // moving a file/folder within the same mount point
823827 } elseif ($ storage1 === $ storage2 ) {
824828 if ($ storage1 ) {
825829 $ result = $ storage1 ->rename ($ internalPath1 , $ internalPath2 );
826830 } else {
827831 $ result = false ;
828832 }
829- // moving a file/folder between storages (from $storage1 to $storage2)
833+ // moving a file/folder between storages (from $storage1 to $storage2)
830834 } else {
831835 $ result = $ storage2 ->moveFromStorage ($ storage1 , $ internalPath1 , $ internalPath2 );
832836 }
833837
834- if ((Cache \Scanner::isPartialFile ($ path1 ) && !Cache \Scanner::isPartialFile ($ path2 )) && $ result !== false ) {
838+ if ((Cache \Scanner::isPartialFile ($ source ) && !Cache \Scanner::isPartialFile ($ target )) && $ result !== false ) {
835839 // if it was a rename from a part file to a regular file it was a write and not a rename operation
836840 $ this ->writeUpdate ($ storage2 , $ internalPath2 );
837841 } elseif ($ result ) {
@@ -842,32 +846,36 @@ public function rename($path1, $path2) {
842846 } catch (\Exception $ e ) {
843847 throw $ e ;
844848 } finally {
845- $ this ->changeLock ($ path1 , ILockingProvider::LOCK_SHARED , true );
846- $ this ->changeLock ($ path2 , ILockingProvider::LOCK_SHARED , true );
849+ $ this ->changeLock ($ source , ILockingProvider::LOCK_SHARED , true );
850+ $ this ->changeLock ($ target , ILockingProvider::LOCK_SHARED , true );
847851 }
848852
849- if ((Cache \Scanner::isPartialFile ($ path1 ) && !Cache \Scanner::isPartialFile ($ path2 )) && $ result !== false ) {
853+ if ((Cache \Scanner::isPartialFile ($ source ) && !Cache \Scanner::isPartialFile ($ target )) && $ result !== false ) {
850854 if ($ this ->shouldEmitHooks ()) {
851- $ this ->emit_file_hooks_post ($ exists , $ path2 );
855+ $ this ->emit_file_hooks_post ($ exists , $ target );
852856 }
853857 } elseif ($ result ) {
854- if ($ this ->shouldEmitHooks ($ path1 ) and $ this ->shouldEmitHooks ($ path2 )) {
855- \OC_Hook::emit (
856- Filesystem::CLASSNAME ,
857- Filesystem::signal_post_rename,
858- [
859- Filesystem::signal_param_oldpath => $ this ->getHookPath ($ path1 ),
860- Filesystem::signal_param_newpath => $ this ->getHookPath ($ path2 )
861- ]
862- );
858+ if ($ this ->shouldEmitHooks ($ source ) && $ this ->shouldEmitHooks ($ target )) {
859+ $ sourcePath = $ this ->getHookPath ($ source );
860+ $ targetPath = $ this ->getHookPath ($ target );
861+ if ($ sourcePath !== null && $ targetPath !== null ) {
862+ \OC_Hook::emit (
863+ Filesystem::CLASSNAME ,
864+ Filesystem::signal_post_rename,
865+ [
866+ Filesystem::signal_param_oldpath => $ sourcePath ,
867+ Filesystem::signal_param_newpath => $ targetPath ,
868+ ]
869+ );
870+ }
863871 }
864872 }
865873 }
866874 } catch (\Exception $ e ) {
867875 throw $ e ;
868876 } finally {
869- $ this ->unlockFile ($ path1 , ILockingProvider::LOCK_SHARED , true );
870- $ this ->unlockFile ($ path2 , ILockingProvider::LOCK_SHARED , true );
877+ $ this ->unlockFile ($ source , ILockingProvider::LOCK_SHARED , true );
878+ $ this ->unlockFile ($ target , ILockingProvider::LOCK_SHARED , true );
871879 }
872880 }
873881 return $ result ;
0 commit comments