1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Server Issue Avatar Upload - Cloud

Discussion in 'Resolved Bug Reports' started by Tim Aldridge, May 18, 2011.

  1. Tim Aldridge

    Tim Aldridge Member

    We discovered an interesting bug when trying to upload low KB files on cloud servers. Anything smaller than 32kb would throw a rename error. Apparently on a cloud server, the rename throws an exception faster than the cloud to check if the file already exists. In Avatar.php, we added this small try/catch and now any size avatar will work.

    PHP:
    protected function _writeAvatar($userId$size$tempFile)
        {
            if (!
    in_array($sizearray_keys(self::$_sizes)))
            {
                throw new 
    XenForo_Exception('Invalid avatar size.');
            }

            
    $filePath $this->getAvatarFilePath($userId$size);
            
    $directory dirname($filePath);

            if (
    XenForo_Helper_File::createDirectory($directorytrue) && is_writable($directory))
            {
                if (
    file_exists($filePath))
                {
                    
    unlink($filePath);
                }

                try {
                    
    $success rename($tempFile$filePath);
                } catch (
    Exception $e) {
                    
    $success file_exists($filePath);
                }

                if (
    $success)
                {
                    
    XenForo_Helper_File::makeWritableByFtpUser($filePath);
                }

                return 
    $success;
            }
            else
            {
                return 
    false;
            }
        }
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    I've moved this to bugs for now, just in case the guys want to make any changes.
     
  3. Mike

    Mike XenForo Developer Staff Member

    That seems like a bug with the cloud filesystem them - it's very misleading to error on rename if it actually works.
     
  4. Tim Aldridge

    Tim Aldridge Member

    It looks like it's related to a small amount of latency and the rename function errors out on small files because it can't see them immediately after return
     
  5. Mike

    Mike XenForo Developer Staff Member

    If it's a latency thing, then a synchronous action (FS modification) is acting asynchronously and that's just going to introduce all sorts of errors. This really looks like a server issue; it just seems to violate the expected behavior.

    What wass the exception anyway?
     

Share This Page