View | Details | Raw Unified | Return to bug 38489
Collapse All | Expand All

(-)a/Koha/File/Transport/FTP.pm (-4 / +28 lines)
Lines 141-155 sub change_directory { Link Here
141
141
142
=head3 list_files
142
=head3 list_files
143
143
144
    my @files = $server->list_files;
144
    my $files = $server->list_files;
145
145
146
Returns an array of filenames found in the current directory of the server connection.
146
Returns an array reference of hashrefs with file information found in the current directory of the server connection.
147
Each hashref contains: filename, longname, size, perms.
147
148
148
=cut
149
=cut
149
150
150
sub list_files {
151
sub list_files {
151
    my ($self) = @_;
152
    my ($self) = @_;
152
    my $file_list = $self->{connection}->ls or return $self->_abort_operation();
153
154
    # Get detailed listing using dir() for consistency with SFTP format
155
    my $detailed_list = $self->{connection}->dir or return $self->_abort_operation();
156
157
    # Convert to hash format consistent with SFTP
158
    my @file_list;
159
    foreach my $line ( @{$detailed_list} ) {
160
161
        # Parse FTP dir output (similar to ls -l format)
162
        # Example: "-rw-r--r-- 1 user group 1234 Jan 01 12:00 filename.txt"
163
        if ( $line =~ /^([d\-rwx]+)\s+\S+\s+\S+\s+\S+\s+(\d+)\s+(.+?)\s+(.+)$/ ) {
164
            my ( $perms, $size, $date_part, $filename ) = ( $1, $2, $3, $4 );
165
166
            # Skip directories (start with 'd')
167
            next if $perms =~ /^d/;
168
169
            push @file_list, {
170
                filename => $filename,
171
                longname => $line,
172
                size     => $size,
173
                perms    => $perms
174
            };
175
        }
176
    }
153
177
154
    $self->add_message(
178
    $self->add_message(
155
        {
179
        {
Lines 159-165 sub list_files { Link Here
159
        }
183
        }
160
    );
184
    );
161
185
162
    return $file_list;
186
    return \@file_list;
163
}
187
}
164
188
165
=head3 rename_file
189
=head3 rename_file
(-)a/Koha/File/Transport/Local.pm (-5 / +23 lines)
Lines 259-267 sub change_directory { Link Here
259
259
260
=head3 list_files
260
=head3 list_files
261
261
262
    my @files = $server->list_files;
262
    my $files = $server->list_files;
263
263
264
Returns an array of filenames found in the current directory.
264
Returns an array reference of hashrefs with file information found in the current directory.
265
Each hashref contains: filename, longname, size, perms, mtime.
265
266
266
=cut
267
=cut
267
268
Lines 302-310 sub list_files { Link Here
302
303
303
    my @files;
304
    my @files;
304
    while ( defined( my $file = $dir_handle->read ) ) {
305
    while ( defined( my $file = $dir_handle->read ) ) {
305
        next if $file =~ /^\.\.?$/;                                 # Skip . and ..
306
        next if $file =~ /^\.\.?$/;    # Skip . and ..
306
        next unless -f File::Spec->catfile( $directory, $file );    # Only files
307
        my $full_path = File::Spec->catfile( $directory, $file );
307
        push @files, $file;
308
        next unless -f $full_path;     # Only files
309
310
        # Get file stats for consistency with SFTP format
311
        my @stat  = stat($full_path);
312
        my $size  = $stat[7] || 0;
313
        my $mtime = $stat[9] || 0;
314
        my $mode  = $stat[2] || 0;
315
316
        # Create permissions string (simplified)
317
        my $perms = sprintf( "%04o", $mode & oct('07777') );
318
319
        push @files, {
320
            filename => $file,
321
            longname => sprintf( "%s %8d %s %s", $perms, $size, scalar( localtime($mtime) ), $file ),
322
            size     => $size,
323
            perms    => $perms,
324
            mtime    => $mtime
325
        };
308
    }
326
    }
309
    $dir_handle->close;
327
    $dir_handle->close;
310
328
(-)a/Koha/File/Transport/SFTP.pm (-3 / +3 lines)
Lines 171-179 sub change_directory { Link Here
171
171
172
=head3 list_files
172
=head3 list_files
173
173
174
    my @files = $server->list_files;
174
    my $files = $server->list_files;
175
175
176
Returns an array of filenames found in the current directory of the server connection.
176
Returns an array reference of hashrefs with file information found in the current directory of the server connection.
177
Each hashref contains: filename, longname, a (attributes).
177
178
178
=cut
179
=cut
179
180
180
- 

Return to bug 38489