Skip to content

Error after renaming files and folders, despite being successful

When renaming a file or folder, I receive an Error: Unable to rename "filename/ foldername". This happens even though the renaming was successful.

Using latest dev (2013-Mar-24) and elfinder lib.

borovinskiy commented 5 years ago

for rename files (not folders) I add method rename in class elFinderVolumeDrupal

file is: elfinder/inc/elfinder.drupalfs.driver.inc

 /**
         * Rename file and return file info
         *
         * @param  string  $hash  file hash
         * @param  string  $name  new file name
         * @return array|false
         * @author Dmitry (dio) Levashov
         **/
        public function rename($hash, $name) {

                if ($this->commandDisabled('rename')) {
                        return $this->setError(elFinder::ERROR_PERM_DENIED);
                }

                if (!$this->nameAccepted($name)) {
                        return $this->setError(elFinder::ERROR_INVALID_NAME, $name);
                }

                if (!($file = $this->file($hash))) {
                        return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
                }

                if ($name == $file['name']) {
                        return $file;
                }

                if (!empty($file['locked'])) {
                        return $this->setError(elFinder::ERROR_LOCKED, $file['name']);
                }

                $path = $this->decode($hash);
                $dir  = $this->_dirname($path);
                $stat = $this->stat($this->_joinPath($dir, $name));
                if ($stat) {
                       return $this->setError(elFinder::ERROR_EXISTS, $name);
                }

                if (!$this->allowCreate($dir, $name)) {
                        return $this->setError(elFinder::ERROR_PERM_DENIED);
                }

                $this->rmTmb($file); // remove old name tmbs, we cannot do this after dir move
                if (($path = $this->_move($path, $dir, $name))) {
                        drupal_json_output(array('added'=>array($this->cache[$path]),'removed'=>array())); exit;    
                        $this->clearcache();
                        return $this->stat($path);
                }
                return false;
        }

it method have drupal_json_output, what not usage in original rename method into library/elfinder/php/elFinderVolumeDriver.class.php

gabriel.achille commented 4 years ago

elfinder-renaming-files-folders-1965012-4.patch

Hi I bundled the patch proposed by borovinskiy in a file (see attached). This is just to get rid of the error message, but for me it does not solve completely the problem as i need to refresh the page afterwards to have the new name taken in account by elfinder. It is the return value of this operation that seems to be the problem for me... need works.

HugoJ CreditAttribution: HugoJ as a volunteer commented 3 years ago

Hi,

I tried this (in file elfinder/inc/elfinder.drupalfs.driver.inc function "function rename($hash, $name)"):

change this :

return $this->stat($file);

to

return $this->stat($dir . '/' . $name);

bwaindwain commented 2 years ago

elfinder-renaming-files-folders-1965012-6.patch

here's a patch that returns some better values and doesn't trigger php notices in the log. I'm able to rename a file and then delete it without any problems. thx @gabriel.achille

NWOM commented about a year ago

The latest patch seems to not work quite yet. It appears it reduces how often the error is shown, however it is still reproducible when renaming a folder twice in a row in a short period of time.