]>
git.p6c8.net - devedit.git/blob - modules/File/Access.pm
4 # Dev-Editor - Module File::Access
6 # Some simple routines for doing things with files
7 # with only one command
9 # Author: Patrick Canterino <patshaping@gmx.net>
10 # Last modified: 2004-08-05
21 use base qw(Exporter);
32 # Change the group of files or directories
34 # Params: 1. Group name or group ID
37 # Return: Number of files group successfully changed
42 my ($group,@files) = @_;
43 my $gid = ($group !~ /^\d+$/) ?
getgrnam($group) : $group;
46 return chown(-1,$gid,@files);
51 # Collect the files and directories in a directory
55 # Return: Hash reference: dirs => directories
63 return unless(-d
$dir);
65 # Get all the entries in the directory
67 opendir(DIR
,$dir) or return;
68 my @entries = readdir(DIR
);
69 closedir(DIR
) or return;
73 @entries = sort {uc($a) cmp uc($b)} @entries;
78 foreach my $entry(@entries)
80 next if($entry eq "." || $entry eq "..");
82 if(-d
$dir."/".$entry)
92 return {dirs
=> \
@dirs, files
=> \
@files};
97 # Create a file, but only if it doesn't already exist
99 # (I wanted to use O_EXCL for this, but `perldoc -f sysopen`
100 # doesn't say that it is available on every system - so I
101 # created this workaround using O_RDONLY and O_CREAT)
103 # Params: File to create
105 # Return: true on success;
106 # false on error or if the file already exists
115 sysopen(FILE
,$file,O_RDONLY
| O_CREAT
) or return;
116 close(FILE
) or return;
123 # Read out a file completely
127 # Return: Contents of the file (Scalar Reference)
134 sysopen(FILE
,$file,O_RDONLY
) or return;
135 read(FILE
, my $content, -s
$file);
136 close(FILE
) or return;
146 # 2. File content as Scalar Reference
148 # Return: Status code (Boolean)
152 my ($file,$content) = @_;
155 sysopen(FILE
,$file,O_WRONLY
| O_CREAT
| O_TRUNC
) or return;
156 print FILE
$$content or do { close(FILE
); return };
157 close(FILE
) or return;
164 # Remove a file from the list of files in use
166 # Params: 1. File::UseList object
173 my ($uselist,$file) = @_;
175 $uselist->remove_file($file);
181 # it's true, baby ;-)
patrick-canterino.de