Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

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.

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

get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false)   X-Ref
Get a remote filepath for the specified stored 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.
return: string The full path to the content file

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

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

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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

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

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

param: stored_file $file stored_file instance
return: bool success

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.

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

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.

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

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.

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