Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

Core file system class definition.

Copyright: 2017 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 536 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: file_system_filedir  - X-Ref

File system class used for low level access to real files in filedir.

__construct()   X-Ref
Perform any custom setup for this type of file_system.


get_local_path_from_hash($contenthash, $fetchifnotfound = false)   X-Ref
Get the full path for the specified hash, including the path to the filedir.

return: string The full path to the content file
param: string $contenthash The content hash
param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.

get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false)   X-Ref
Get a remote filepath for the specified stored file.

return: string The full path to the content file
param: stored_file $file The file to fetch the path for
param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.

get_remote_path_from_storedfile(stored_file $file)   X-Ref
Get a remote filepath for the specified stored file.

return: string full path to pool file with file content
param: stored_file $file The file to serve.

get_remote_path_from_hash($contenthash)   X-Ref
Get the full path for the specified hash, including the path to the filedir.

return: string The full path to the content file
param: string $contenthash The content hash

get_fulldir_from_storedfile(stored_file $file)   X-Ref
Get the full directory to the stored file, including the path to the
filedir, and the directory which the file is actually in.

Note: This function does not ensure that the file is present on disk.

return: string The full path to the content directory
param: stored_file $file The file to fetch details for.

get_fulldir_from_hash($contenthash)   X-Ref
Get the full directory to the stored file, including the path to the
filedir, and the directory which the file is actually in.

return: string The full path to the content directory
param: string $contenthash The content hash

get_contentdir_from_hash($contenthash)   X-Ref
Get the content directory for the specified content hash.
This is the directory that the file will be in, but without the
fulldir.

return: string The directory within filedir
param: string $contenthash The content hash

get_contentpath_from_hash($contenthash)   X-Ref
Get the content path for the specified content hash within filedir.

This does not include the filedir, and is often used by file systems
as the object key for storage and retrieval.

return: string The filepath within filedir
param: string $contenthash The content hash

get_trash_fulldir_from_hash($contenthash)   X-Ref
Get the full directory for the specified hash in the trash, including the path to the
trashdir, and the directory which the file is actually in.

return: string The full path to the trash directory
param: string $contenthash The content hash

get_trash_fullpath_from_hash($contenthash)   X-Ref
Get the full path for the specified hash in the trash, including the path to the trashdir.

return: string The full path to the trash file
param: string $contenthash The content hash

copy_content_from_storedfile(stored_file $file, $target)   X-Ref
Copy content of file to given pathname.

return: bool success
param: stored_file $file The file to be copied
param: string $target real path to the new file

recover_file(stored_file $file)   X-Ref
Tries to recover missing content of file from trash.

return: bool success
param: stored_file $file stored_file instance

remove_file($contenthash)   X-Ref
Marks pool file as candidate for deleting.

param: string $contenthash

cron()   X-Ref
Cleanup the trash directory.


empty_trash()   X-Ref
No description

add_file_from_path($pathname, $contenthash = null)   X-Ref
Add the supplied file to the file system.

Note: If overriding this function, it is advisable to store the file
in the path returned by get_local_path_from_hash as there may be
subsequent uses of the file in the same request.

return: array (contenthash, filesize, newfile)
param: string $pathname Path to file currently on disk
param: string $contenthash SHA1 hash of content if known (performance only)

check_file_exists_and_get_size(string $hashfile)   X-Ref
Checks if the file exists and gets its size. This function avoids a specific issue with
networked file systems if they incorrectly report the file exists, but then decide it doesn't
as soon as you try to get the file size.

return: int|null Null if the file does not exist, or the result of filesize(), or -1 if error
param: string $hashfile File to check

add_file_from_string($content)   X-Ref
Add a file with the supplied content to the file system.

Note: If overriding this function, it is advisable to store the file
in the path returned by get_local_path_from_hash as there may be
subsequent uses of the file in the same request.

return: array (contenthash, filesize, newfile)
param: string $content file content - binary string