Difference between revisions of "Talk:RecycleBin"
From SME Server
Jump to navigationJump to search (open bugs) |
Unnilennium (talk | contribs) |
||
Line 6: | Line 6: | ||
[[User:Snoble|Snoble]] 14:49, 27 November 2007 (MST) | [[User:Snoble|Snoble]] 14:49, 27 November 2007 (MST) | ||
+ | |||
+ | from firewall service | ||
+ | |||
+ | https://git.fws.fr/fws/ipasserelle-base/src/branch/master/root/etc/cron.daily/purge-homes-recycle<syntaxhighlight lang="perl"> | ||
+ | #!/usr/bin/perl -w | ||
+ | |||
+ | #---------------------------------------------------------------------- | ||
+ | # Copyright (C) 2012 Firewall Services | ||
+ | # daniel@firewall-services.com | ||
+ | # | ||
+ | # This program is free software; you can redistribute it and/or modify | ||
+ | # it under the terms of the GNU General Public License as published by | ||
+ | # the Free Software Foundation; either version 2 of the License, or | ||
+ | # (at your option) any later version. | ||
+ | # | ||
+ | # This program is distributed in the hope that it will be useful, | ||
+ | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
+ | # GNU General Public License for more details. | ||
+ | # | ||
+ | # You should have received a copy of the GNU General Public License | ||
+ | # along with this program; if not, write to the Free Software | ||
+ | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
+ | #---------------------------------------------------------------------- | ||
+ | |||
+ | use esmith::AccountsDB; | ||
+ | use esmith::ConfigDB; | ||
+ | use File::Find; | ||
+ | use File::stat; | ||
+ | |||
+ | my $c = esmith::ConfigDB->open_ro || die "Error opening ConfigDB\n"; | ||
+ | my $a = esmith::AccountsDB->open_ro || die "Error opening AccountsDB\n"; | ||
+ | my $smb = $c->get('smb') || die "Can't find the smb service in the ConfigDB\n"; | ||
+ | my $recycle = $smb->prop('RecycleBin') || 'disabled'; | ||
+ | our $retention = $smb->prop('RecycleBinRetention') || 'unlimited'; | ||
+ | $retention = 'unlimited' unless ($retention =~ m/^\d+$/); | ||
+ | |||
+ | exit(0) if (($recycle ne 'enabled') || ($retention eq 'unlimited')); | ||
+ | |||
+ | # Convert retention in seconds | ||
+ | $retention = 60*60*24*$retention; | ||
+ | |||
+ | foreach my $user ($a->get_all_by_prop(type=>'user')){ | ||
+ | my $key = $user->key; | ||
+ | # Skip the user if RecycleBin doesn't exists | ||
+ | next unless (-d "/home/e-smith/files/users/$key/home/Recycle Bin"); | ||
+ | finddepth(\&remove, "/home/e-smith/files/users/$key/home/Recycle Bin/"); | ||
+ | } | ||
+ | |||
+ | sub remove{ | ||
+ | # Remove files with last modification older than $retention | ||
+ | if ( -f ){ | ||
+ | my $mtime = stat($_)->mtime; | ||
+ | (time() - $mtime > $retention) && unlink($_); | ||
+ | } | ||
+ | # Remove empty directories | ||
+ | elsif ( -d ){ | ||
+ | (scalar <"$_/*">) || rmdir("$_"); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> |
Latest revision as of 22:20, 29 November 2022
Shouldn't this be added to one of the manuals? - Cactus 08:12, 27 November 2007 (MST)
there are still open bugs, amongst others
http://bugs.contribs.org/show_bug.cgi?id=1734
Snoble 14:49, 27 November 2007 (MST)
from firewall service
https://git.fws.fr/fws/ipasserelle-base/src/branch/master/root/etc/cron.daily/purge-homes-recycle
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# Copyright (C) 2012 Firewall Services
# daniel@firewall-services.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
use esmith::AccountsDB;
use esmith::ConfigDB;
use File::Find;
use File::stat;
my $c = esmith::ConfigDB->open_ro || die "Error opening ConfigDB\n";
my $a = esmith::AccountsDB->open_ro || die "Error opening AccountsDB\n";
my $smb = $c->get('smb') || die "Can't find the smb service in the ConfigDB\n";
my $recycle = $smb->prop('RecycleBin') || 'disabled';
our $retention = $smb->prop('RecycleBinRetention') || 'unlimited';
$retention = 'unlimited' unless ($retention =~ m/^\d+$/);
exit(0) if (($recycle ne 'enabled') || ($retention eq 'unlimited'));
# Convert retention in seconds
$retention = 60*60*24*$retention;
foreach my $user ($a->get_all_by_prop(type=>'user')){
my $key = $user->key;
# Skip the user if RecycleBin doesn't exists
next unless (-d "/home/e-smith/files/users/$key/home/Recycle Bin");
finddepth(\&remove, "/home/e-smith/files/users/$key/home/Recycle Bin/");
}
sub remove{
# Remove files with last modification older than $retention
if ( -f ){
my $mtime = stat($_)->mtime;
(time() - $mtime > $retention) && unlink($_);
}
# Remove empty directories
elsif ( -d ){
(scalar <"$_/*">) || rmdir("$_");
}
}