Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 magnus 1
package DebPool::Util;
2
 
3
###
4
#
5
# DebPool::Util - Module to contain various utility routines
6
#
7
# Copyright 2004 Joel Aelwyn. All rights reserved.
8
# 
9
# Redistribution and use in source and binary forms, with or without
10
# modification, are permitted provided that the following conditions
11
# are met:
12
# 1. Redistributions of source code must retain the above copyright
13
#    notice, this list of conditions and the following disclaimer.
14
# 2. Redistributions in binary form must reproduce the above copyright
15
#    notice, this list of conditions and the following disclaimer in the
16
#    documentation and/or other materials provided with the distribution.
17
# 3. Neither the name of the Author nor the names of any contributors
18
#    may be used to endorse or promote products derived from this software
19
#    without specific prior written permission.
20
# 
21
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
# SUCH DAMAGE.
32
#
33
# $Id: Util.pm 27 2004-11-07 03:06:59Z joel $
34
#
35
###
36
 
37
# We use 'our', so we must have at least Perl 5.6
38
 
39
require 5.006_000;
40
 
41
# Always good ideas.
42
 
43
use strict;
44
use warnings;
45
 
46
use File::Copy;
47
 
48
### Module setup
49
 
50
BEGIN {
51
    use Exporter ();
52
    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
53
 
54
    # Version checking
55
    $VERSION = '0.1.5';
56
 
57
    @ISA = qw(Exporter);
58
 
59
    @EXPORT = qw(
60
    );
61
 
62
    @EXPORT_OK = qw(
63
        &Move_File
64
    );
65
 
66
    %EXPORT_TAGS = (
67
        'functions' => [qw(&Move_File)],
68
        'vars' => [qw()],
69
    );
70
}
71
 
72
### Exported package globals
73
 
74
# None
75
 
76
### Non-exported package globals
77
 
78
# Thread-safe? What's that? Package global error value. We don't export
79
# this directly, because it would conflict with other modules.
80
 
81
our($Error);
82
 
83
### File lexicals
84
 
85
# None
86
 
87
### Constant functions
88
 
89
# None
90
 
91
### Meaningful functions
92
 
93
# Move_File($orig, $new, $mode)
94
#
95
# Move an file from $orig to $new by copying, and set the file mode
96
# of the new file according to the variables given.
97
#
98
# Returns 1 if successful, 0 if not (and sets $Error)
99
 
100
sub Move_File {
101
    my($orig) = shift(@_);
102
    my($new) = shift(@_);
103
    my($mode) = shift(@_);
104
 
105
    if (!copy($orig, $new)) {
106
        $Error = $!;
107
        return 0;
108
    }
109
 
110
    if (!chmod($mode, $new)) {
111
        $Error = $!;
112
        return 0;
113
    }
114
 
115
    if (!unlink($orig)) {
116
        $Error = $!;
117
        return 0;
118
    }
119
 
120
    return 1;
121
}
122
 
123
END {}
124
 
125
1;
126
 
127
__END__
128
 
129
# vim:set tabstop=4 expandtab: