Bugzilla – Attachment 187153 Details for
Bug 38489
EDI should be updated to use the new FTP/SFTP Servers management page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38489: Standardize list_files API across all transport classes
Bug-38489-Standardize-listfiles-API-across-all-tra.patch (text/plain), 5.04 KB, created by
Martin Renvoize (ashimema)
on 2025-10-01 07:03:45 UTC
(
hide
)
Description:
Bug 38489: Standardize list_files API across all transport classes
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-10-01 07:03:45 UTC
Size:
5.04 KB
patch
obsolete
>From 3f94aceabdc99bfb5996fafb7f55ed0f78f860d8 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Tue, 23 Sep 2025 20:41:09 +0100 >Subject: [PATCH] Bug 38489: Standardize list_files API across all transport > classes > >Fix API inconsistency where different transport types returned different >formats from list_files(): > >- SFTP: returned array of hashrefs with detailed file information >- FTP: returned simple array of filenames >- Local: returned simple array of filenames > >Now all transports return an array reference of hashrefs with consistent >structure containing filename, longname, and additional metadata. > >This eliminates the need for workarounds like the ref($file) eq 'HASH' >check in EDI code and provides a more robust, consistent API. > >Sponsored-by: ByWater Solutions >Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk> >--- > Koha/File/Transport/FTP.pm | 32 ++++++++++++++++++++++++++++---- > Koha/File/Transport/Local.pm | 28 +++++++++++++++++++++++----- > Koha/File/Transport/SFTP.pm | 5 +++-- > 3 files changed, 54 insertions(+), 11 deletions(-) > >diff --git a/Koha/File/Transport/FTP.pm b/Koha/File/Transport/FTP.pm >index cc215fc83c9..c6208d4cc24 100644 >--- a/Koha/File/Transport/FTP.pm >+++ b/Koha/File/Transport/FTP.pm >@@ -141,15 +141,39 @@ sub change_directory { > > =head3 list_files > >- my @files = $server->list_files; >+ my $files = $server->list_files; > >-Returns an array of filenames found in the current directory of the server connection. >+Returns an array reference of hashrefs with file information found in the current directory of the server connection. >+Each hashref contains: filename, longname, size, perms. > > =cut > > sub list_files { > my ($self) = @_; >- my $file_list = $self->{connection}->ls or return $self->_abort_operation(); >+ >+ # Get detailed listing using dir() for consistency with SFTP format >+ my $detailed_list = $self->{connection}->dir or return $self->_abort_operation(); >+ >+ # Convert to hash format consistent with SFTP >+ my @file_list; >+ foreach my $line ( @{$detailed_list} ) { >+ >+ # Parse FTP dir output (similar to ls -l format) >+ # Example: "-rw-r--r-- 1 user group 1234 Jan 01 12:00 filename.txt" >+ if ( $line =~ /^([d\-rwx]+)\s+\S+\s+\S+\s+\S+\s+(\d+)\s+(.+?)\s+(.+)$/ ) { >+ my ( $perms, $size, $date_part, $filename ) = ( $1, $2, $3, $4 ); >+ >+ # Skip directories (start with 'd') >+ next if $perms =~ /^d/; >+ >+ push @file_list, { >+ filename => $filename, >+ longname => $line, >+ size => $size, >+ perms => $perms >+ }; >+ } >+ } > > $self->add_message( > { >@@ -159,7 +183,7 @@ sub list_files { > } > ); > >- return $file_list; >+ return \@file_list; > } > > =head3 rename_file >diff --git a/Koha/File/Transport/Local.pm b/Koha/File/Transport/Local.pm >index 22ef93bc5b3..729a7f4a13b 100644 >--- a/Koha/File/Transport/Local.pm >+++ b/Koha/File/Transport/Local.pm >@@ -259,9 +259,10 @@ sub change_directory { > > =head3 list_files > >- my @files = $server->list_files; >+ my $files = $server->list_files; > >-Returns an array of filenames found in the current directory. >+Returns an array reference of hashrefs with file information found in the current directory. >+Each hashref contains: filename, longname, size, perms, mtime. > > =cut > >@@ -302,9 +303,26 @@ sub list_files { > > my @files; > while ( defined( my $file = $dir_handle->read ) ) { >- next if $file =~ /^\.\.?$/; # Skip . and .. >- next unless -f File::Spec->catfile( $directory, $file ); # Only files >- push @files, $file; >+ next if $file =~ /^\.\.?$/; # Skip . and .. >+ my $full_path = File::Spec->catfile( $directory, $file ); >+ next unless -f $full_path; # Only files >+ >+ # Get file stats for consistency with SFTP format >+ my @stat = stat($full_path); >+ my $size = $stat[7] || 0; >+ my $mtime = $stat[9] || 0; >+ my $mode = $stat[2] || 0; >+ >+ # Create permissions string (simplified) >+ my $perms = sprintf( "%04o", $mode & oct('07777') ); >+ >+ push @files, { >+ filename => $file, >+ longname => sprintf( "%s %8d %s %s", $perms, $size, scalar( localtime($mtime) ), $file ), >+ size => $size, >+ perms => $perms, >+ mtime => $mtime >+ }; > } > $dir_handle->close; > >diff --git a/Koha/File/Transport/SFTP.pm b/Koha/File/Transport/SFTP.pm >index a2a37dd0186..d0abdd69d3a 100644 >--- a/Koha/File/Transport/SFTP.pm >+++ b/Koha/File/Transport/SFTP.pm >@@ -171,9 +171,10 @@ sub change_directory { > > =head3 list_files > >- my @files = $server->list_files; >+ my $files = $server->list_files; > >-Returns an array of filenames found in the current directory of the server connection. >+Returns an array reference of hashrefs with file information found in the current directory of the server connection. >+Each hashref contains: filename, longname, a (attributes). > > =cut > >-- >2.51.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38489
:
175204
|
175205
|
175206
|
175207
|
176118
|
176119
|
176161
|
185324
|
186819
|
186820
|
186845
|
186846
|
186847
|
186848
|
186849
|
186850
|
186851
|
186852
|
186854
|
187080
|
187081
|
187082
|
187083
|
187084
|
187085
|
187086
|
187087
|
187088
|
187089
|
187108
|
187147
|
187148
|
187149
|
187150
|
187151
|
187152
|
187153
|
187154
|
187155
|
187156
|
187157
|
187158
|
187159
|
187270
|
187271
|
187272
|
187273
|
187274
|
187275
|
187276
|
187277
|
187278
|
187279
|
187280
|
187281
|
187283
|
187284
|
187285
|
187286
|
187287
|
187288
|
187289
|
187290
|
187291
|
187292
|
187293
|
187294