I've written a  perl script that syncs RHN Sat server config channels to 
spacewalk and it's not handling binary files properly. The Spacewalk 
createOrUpdatePath API call keeps creating txt files rather than binary.

Here's the relevant code. Does anyone have an suggestions?!

                my $file_info = 
$rhn_client->call('configchannel.lookupFileInfo', $rhn_session, $channel, 
["$rhn_file->{'path'}"]);
                my %new_file;
                $new_file{'permissions'} = 
$spw_client->string($file_info->[0]->{'permissions_mode'});
                $new_file{'owner'} = 
$spw_client->string($file_info->[0]->{'owner'});
                $new_file{'group'} = 
$spw_client->string($file_info->[0]->{'group'});
                $new_file{'revision'} = 
$spw_client->int($file_info->[0]->{'revision'});

                if ($file_info->[0]->{'type'} eq 'symlink')
                {
                        my %symlink_info;
                        $symlink_info{'target_path'} = 
$spw_client->string($file_info->[0]->{'target_path'});
                        $symlink_info{'revision'} = 
$spw_client->int($file_info->[0]->{'revision'});
                        
$spw_client->call('configchannel.createOrUpdateSymlink', $spw_session, 
$channel, $file_info->[0]->{'path'}, \%symlink_info);
                }
                elsif ("$file_info->[0]->{'type'}" eq 'directory')
                {
                        $spw_client->call('configchannel.createOrUpdatePath', 
$spw_session, $channel, $file_info->[0]->{'path'}, $spw_client->string(1), 
\%new_file);
                }
                else
                {
                        if ($file_info->[0]->{'binary'}->value == 1)
                        {
                                my $base64_file = 
$rhn_client->call('configchannel.getEncodedFileRevision', $rhn_session, 
$channel, "$rhn_file->{'path'}", $file_info->[0]->{'revision'});
                                $new_file{'contents'} = 
$base64_file->{'contents'};
                                $new_file{'contents_enc64'} = 
$spw_client->boolean(1);
                                
$spw_client->call('configchannel.createOrUpdatePath', $spw_session, $channel, 
$base64_file->{'path'}, $spw_client->string(0), \%new_file);
                        }
                        else
                        {
                                $new_file{'contents'} = 
$file_info->[0]->{'contents'};
                                $new_file{'macro-start-delimiter'} = 
$spw_client->string($file_info->[0]->{'macro-start-delimiter'});
                                $new_file{'macro-end-delimiter'} = 
$spw_client->string($file_info->[0]->{'macro-end-delimiter'});
                                
$spw_client->call('configchannel.createOrUpdatePath', $spw_session, $channel, 
$file_info->[0]->{'path'}, $spw_client->string(0), \%new_file);
                        }
                }


Thanks,
--james

_______________________________________________
Spacewalk-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/spacewalk-list

Reply via email to