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.

Comments

jaspher’s picture

Title: Error after renaming files, despite being successful » Error after renaming files and folders, despite being successful
borovinskiy’s picture

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

borovinskiy’s picture

Issue summary: View changes

Edited to include folders.

ph0enix’s picture

Title: Error after renaming files and folders, despite being successful » [patch] Error after renaming files and folders, despite being successful
Assigned: Unassigned » ph0enix
Priority: Normal » Major
Issue summary: View changes
Status: Active » Needs review
gabriel.achille’s picture

Status: Needs review » Needs work
StatusFileSize
new1.96 KB

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’s picture

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’s picture

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

bwaindwain’s picture

Status: Needs work » Needs review
nwom’s picture

Status: Needs review » Needs work

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.

ph0enix’s picture

Status: Needs work » Closed (duplicate)

Moved #26