YaST2 Developers Documentation: YaST2

YaST2

modules/FileUtils.ycp
Module for getting information about files and directories. Their types and sizes and functions for checking, creating and removing them.
  • Lukas Ocilka

This module has an unstable interface.

Imports

  • Popup
  • SCR
  • String

Global Functions

global Exists (string target) -> boolean

Function which determines if the requested file/directory exists.

Parameters:
target
Return value:
true if exists
Example

	FileUtils::Exists ("/tmp") -> true
	FileUtils::Exists ("/tmp/somefile") -> false
global IsDirectory (string target) -> boolean

Function which determines if the requested file/directory is a directory or it is a link to a directory.

Parameters:
target
Return value:
true if it is a directory, nil if doesn't exist
Example

	FileUtils::IsDirectory ("/var") -> true
	FileUtils::IsDirectory ("/var/log/messages") -> false
	FileUtils::IsDirectory ("/does-not-exist") -> nil
global IsFile (string target) -> boolean

Function which determines if the requested file/directory is a regular file or it is a link to a regular file.

Parameters:
target
Return value:
true if it is a regular file, nil if doesn't exist
Example

	FileUtils::IsFile ("/var") -> false
	FileUtils::IsFile ("/var/log/messages") -> true
	FileUtils::IsFile ("/does-not-exist") -> nil
global IsBlock (string target) -> boolean

Function which determines if the requested file/directory is a block file (device) or link to a block device.

Parameters:
target
Return value:
true if it is a block file, nil if doesn't exist
Example

	FileUtils::IsBlock ("/var") -> false
	FileUtils::IsBlock ("/dev/sda2") -> true
	FileUtils::IsBlock ("/dev/does-not-exist") -> nil
global IsFifo (string target) -> boolean

Function which determines if the requested file/directory is a fifo or link to a fifo.

Parameters:
target
Return value:
true if it is a fifo, nil if doesn't exist
global IsLink (string target) -> boolean

Function which determines if the requested file/directory is a link.

Parameters:
target
Return value:
true if it is a link, nil if doesn't exist
global IsSocket (string target) -> boolean

Function which determines if the requested file/directory is a socket or link to a socket.

Parameters:
target
Return value:
true if it is a socket, nil if doesn't exist
global IsCharacterDevice (string target) -> boolean

Function which determines if the requested file/directory is a character device or link to a character device.

Parameters:
target
Return value:
true if it is a charcater device, nil if doesn't exist
global GetFileRealType (string target) -> string

Function returns the real type of requested file/directory. If the file is a link to any object, "link" is returned.

Parameters:
target
Return value:
file type (directory|regular|block|fifo|link|socket|chr_device), nil if doesn't exist
Example

	FileUtils::GetFileRealType ("/var") -> "directory"
	FileUtils::GetFileRealType ("/etc/passwd") -> "file"
	FileUtils::GetFileRealType ("/does-not-exist") -> nil
global GetFileType (string target) -> string

Function returns the type of requested file/directory. If the file is a link to any object, the object's type is returned.

Parameters:
target
Return value:
fle type (directory|regular|block|fifo|link|socket|chr_device), nil if doesn't exist
global GetSize (string target) -> integer

Function which returns the size of requested file/directory.

Parameters:
target
Return value:
file size, -1 if doesn't exist
Example

	FileUtils::GetSize ("/var/log/YaST2") -> 12348
	FileUtils::GetSize ("/does-not-exist") -> -1
global GetOwnerUserID (string target) -> integer

Function which determines the owner's user ID of requested file/directory.

Parameters:
target
Return value:
UID, nil if doesn't exist
Example

	FileUtils::GetOwnerUserID ("/etc/passwd") -> 0
	FileUtils::GetOwnerUserID ("/does-not-exist") -> nil
global GetOwnerGroupID (string target) -> integer

Function which determines the owner's group ID of requested file/directory.

Parameters:
target
Return value:
GID, nil if doesn't exist
Example

	FileUtils::GetOwnerGroupID ("/etc/passwd") -> 0
	FileUtils::GetOwnerGroupID ("/does-not-exist") -> nil
global CheckAndCreatePath (string pathvalue) -> boolean

Checks whether the path (directory) exists and return a boolean value whether everything is OK or user accepted the behavior as despite some errors. If the directory doesn't exist, it offers to create it (and eventually creates it).

Parameters:
pathvalue
Return value:
whether everything was OK or whether user decided to ignore eventual errors
global MD5sum (string target) -> string

Function return the MD5 sum of the file.

Parameters:
target
Return value:
MD5 sum of the file, nil if doesn't exist
Example

	FileUtils::MD5sum ("/etc/passwd") -> "74855f6ac9bf728fccec4792d1dba828"
	FileUtils::MD5sum ("/does-not-exist") -> nil
global Chown (string usergroup, string file, boolean recursive) -> boolean

Changes ownership of a file/directory

Parameters:
usergroup
file
recursive
Return value:
true if succeeded
Example

	FileUtils::Chown ( "somebody:somegroup", "/etc/passwd", false) -> 'chown somebody:somegroup /etc/passwd'
	FileUtils::Chown ( "nobody:nogroup", "/tmp", true) -> 'chown nobody:nogroup -R /tmp'
global Chmod (string modes, string file, boolean recursive) -> boolean

Changes access rights to a file/directory

Parameters:
modes
file
recursive
Return value:
true if succeeded
Example

	FileUtils::Chmod ( "go-rwx", "/etc/passwd", false) -> 'chmod go-rwx /etc/passwd'
	FileUtils::Chmod ( "700", "/tmp", true) -> 'chmod 700 -R /tmp'
global MkTempFile (string template, string usergroup, string modes) -> string

Creates temporary file

Parameters:
template
usergroup
modes
Return value:
resulting file name or nil on failure
Example

	FileUtils::MkTempFile ( "/tmp/tmpfile.XXXX", "somebody:somegroup", "744")
global MkTempDirectory (string template, string usergroup, string modes) -> string

The same as MkTempFile, for directories ('mktemp -d ... '). See above

Parameters:
template
usergroup
modes
Example

	FileUtils::MkTempDirectory ( "/tmp/tmpdir.XXXX", "nobody:nogroup", "go+x") 
global CleanupTemp () -> void

Removes files and dirs created in all previous calls to MkTemp[File|Directory]