|
76 | 76 |
|
77 | 77 | $copy_to_master = 0; |
78 | 78 |
|
79 | | - # If the ics file exists in the master copy we have to compare them, |
80 | | - # otherwise we can just copy the new file into the master directory. |
81 | | - if (-e $master_file) { |
| 79 | + if (-l $new_file) { |
| 80 | + # This is a symlink, copy it in any case. |
| 81 | + |
| 82 | + if (!-e $master_file) { |
| 83 | + print "Creating new symlinkg $new_file...\n"; |
| 84 | + $copy_to_master = 1; |
| 85 | + } elsif (-l $master_file) { |
| 86 | + my $src = readlink($master_file); |
| 87 | + my $dst = readlink($new_file); |
| 88 | + |
| 89 | + if ($src eq $dst) { |
| 90 | + $copy_to_master = 0; |
| 91 | + # print "Symlink $new_file unchanged: $src.\n" |
| 92 | + } else { |
| 93 | + print "Updating symlink $new_file to $src...\n"; |
| 94 | + $copy_to_master = 1; |
| 95 | + } |
| 96 | + |
| 97 | + } else { |
| 98 | + print "Changing $new_file to symlink...\n"; |
| 99 | + $copy_to_master = 1; |
| 100 | + } |
| 101 | + |
| 102 | + } elsif (-l $master_file) { |
| 103 | + $copy_to_master = 1; |
| 104 | + print "Changing $new_file from symlink to real file...\n"; |
| 105 | + |
| 106 | + } elsif (-e $master_file) { |
| 107 | + # If the ics file exists in the master copy we have to compare them, |
| 108 | + # otherwise we can just copy the new file into the master directory. |
82 | 109 | open (MASTERZONEFILE, "$master_file") |
83 | 110 | || die "Can't open file: $master_file"; |
84 | 111 | undef $/; |
|
131 | 158 | make_path $directories or die "Failed to create path: $directories"; |
132 | 159 | } |
133 | 160 |
|
134 | | - open (MASTERZONEFILE, ">$master_file") |
135 | | - || die "Can't create file: $master_file"; |
136 | | - print MASTERZONEFILE $new_contents; |
137 | | - close (MASTERZONEFILE); |
| 161 | + if ( -e $master_file ) { |
| 162 | + # delete old file so we don't have issues with symlinks |
| 163 | + unlink($master_file) |
| 164 | + } |
| 165 | + |
| 166 | + if ( -l $new_file ) { |
| 167 | + my $dst = readlink($new_file) || die "Can't read symlink $new_file."; |
| 168 | + |
| 169 | + print "Creating symlink to $dst in $master_file.\n"; |
| 170 | + symlink $dst, $master_file || die "Can't create symlink $new_file."; |
| 171 | + } else { |
| 172 | + open (MASTERZONEFILE, ">$master_file") |
| 173 | + || die "Can't create file: $master_file"; |
| 174 | + print MASTERZONEFILE $new_contents; |
| 175 | + close (MASTERZONEFILE); |
| 176 | + } |
138 | 177 | } |
139 | 178 | } |
140 | 179 | } |
|
0 commit comments