Skip to content

Commit

Permalink
Follow symlink at command line URL (Fixes #240)
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Jan 6, 2024
1 parent 9889977 commit e322141
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
58 changes: 54 additions & 4 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@


#include <QApplication>
#include <QClipboard>
#include <QCloseEvent>
#include <QMouseEvent>
#include <QMessageBox>
#include <QFileDialog>
#include <QClipboard>
#include <QFileInfo>
#include <QMessageBox>
#include <QMouseEvent>

#include "MainWindow.h"
#include "ActionManager.h"
Expand Down Expand Up @@ -574,8 +575,10 @@ void MainWindow::openUrl( const QString & url )
}


void MainWindow::openDir( const QString & url )
void MainWindow::openDir( const QString & origUrl )
{
QString url = handleSymLink( origUrl );

try
{
if ( url.startsWith( "/" ) )
Expand Down Expand Up @@ -614,6 +617,53 @@ void MainWindow::showOpenDirErrorPopup( const SysCallFailedException & ex )
}


QString MainWindow::handleSymLink( const QString & origUrl ) const
{
QString url( origUrl );
QFileInfo urlInfo( url );

if ( urlInfo.isSymLink() )
{
PanelMessage * msg = 0;

if ( urlInfo.exists() )
{
QString target = urlInfo.canonicalFilePath();

logInfo() << "Following symlink \"" << url
<<"\" to target \"" << target << "\"" << endl;

msg = new PanelMessage( _ui->messagePanel );
CHECK_NEW( msg );

msg->setHeading( tr( "Following symbolic link" ) );
msg->setText( tr( "%1 is a symbolic link to %2" )
.arg( url ).arg( target ) );
_ui->messagePanel->add( msg );

url = target;
}
else
{
logError() << "Broken symlink";

msg = new PanelMessage( _ui->messagePanel );
CHECK_NEW( msg );

msg->setHeading( tr( "Broken symbolic link" ) );
msg->setText( tr( "%1 is a broken symbolic link to %2" )
.arg( url ).arg( urlInfo.symLinkTarget() ) );
msg->setIcon( QPixmap( ":/icons/dialog-warning.png" ) );
}

if ( msg )
_ui->messagePanel->add( msg );
}

return url;
}


void MainWindow::askOpenDir()
{
QString path;
Expand Down
9 changes: 9 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ protected slots:
**/
void showOpenDirErrorPopup( const SysCallFailedException & ex );

/**
* Handle a symlink as an argument to reading a new directory tree
* e.g. in openDir(): Follow the symlink and return the target URL.
*
* If it is a valid symlink, post a PanelMessage to inform the user about
* it. If it's a broken symlink, post an error as a PanelMessage.
**/
QString handleSymLink( const QString & origUrl ) const;

/**
* Handle mouse buttons: Activate history actions actionGoBack and
* actionGoForward with the "back" and "forward" mouse buttons as well.
Expand Down

0 comments on commit e322141

Please sign in to comment.