Skip to content

Commit

Permalink
Make link target directory configurable (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
edocevoli committed Mar 2, 2019
1 parent 738c03d commit d590361
Show file tree
Hide file tree
Showing 24 changed files with 247 additions and 43 deletions.
8 changes: 8 additions & 0 deletions Admin/Config/miktex-config.ini.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
;; in a shared setup.
${MIKTEX_CONFIG_VALUE_AUTOADMIN} = ${Core_AutoAdmin}

;; System-wide directory in which to create symbolic links to
;; MiKTeX executables.
${MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY} = ${MIKTEX_SYSTEM_LINK_TARGET_DIR}

;; Per-user directory in which to create symbolic links to
;; MiKTeX executables.
${MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY} = ${MIKTEX_USER_LINK_TARGET_DIR}

[${MIKTEX_CONFIG_SECTION_CORE_FILETYPES}.afm]

;; Search path for Adobe font metric (AFM) files.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* luatex 1.10.0

### Fixed issues

* [195](https://github.com/MiKTeX/miktex/issues/195): Add option to change directory for binaries (Linux)

## 2.9.6980 - 2019-02-11

### Fixed issues
Expand Down
12 changes: 12 additions & 0 deletions Documentation/Ref/miktexsetup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ This option requires administrator privileges.</para></listitem>
This option requires administrator privileges.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--common-link-target-directory=<replaceable>dir</replaceable></option></term>
<listitem><para>Set the system-wide directory in which to create
symbolic links to &MiKTeX; executables.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--common-roots=<replaceable>dirs</replaceable></option></term>
<listitem><para>Register additional directories for all users.
Expand Down Expand Up @@ -216,6 +222,12 @@ the current user.</para>
<para>Environment variables (&lt;VARNAME&gt;) can be used. See the example below.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--user-link-target-directory=<replaceable>dir</replaceable></option></term>
<listitem><para>Set the per-user directory in which to create symbolic
links to &MiKTeX; executables.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--user-roots=<replaceable>dirs</replaceable></option></term>
<listitem><para>Register additional directories for the current user.
Expand Down
4 changes: 2 additions & 2 deletions Libraries/MiKTeX/Core/Session/filetypes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* filetypes.cpp: MiKTeX file type registry
Copyright (C) 1996-2018 Christian Schenk
Copyright (C) 1996-2019 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -136,7 +136,7 @@ void SessionImpl::RegisterFileType(FileType fileType)
#elif defined(MIKTEX_EXE_FILE_SUFFIX)
extensions.push_back(MIKTEX_EXE_FILE_SUFFIX);
#endif
PathName localBinDir = GetSpecialPath(MiKTeX::Core::SpecialPath::LocalBinDirectory);
PathName localBinDir = GetSpecialPath(MiKTeX::Core::SpecialPath::LinkTargetDirectory);
localBinDir.Canonicalize();
if (std::find(searchPath.begin(), searchPath.end(), localBinDir.ToString()) == searchPath.end())
{
Expand Down
10 changes: 5 additions & 5 deletions Libraries/MiKTeX/Core/Session/miktex.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* miktex.cpp:
Copyright (C) 1996-2018 Christian Schenk
Copyright (C) 1996-2019 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand All @@ -24,6 +24,7 @@
// FIXME: must come first
#include "core-version.h"

#include <miktex/Core/ConfigNames>
#include <miktex/Core/Directory>
#include <miktex/Core/Environment>
#include <miktex/Core/FileStream>
Expand Down Expand Up @@ -134,18 +135,17 @@ PathName SessionImpl::GetSpecialPath(SpecialPath specialPath)
path = GetMyPrefix(true) / MIKTEX_INTERNAL_BINARY_DESTINATION_DIR;
#endif
break;
case SpecialPath::LocalBinDirectory:
case SpecialPath::LinkTargetDirectory:
#if defined(MIKTEX_WINDOWS)
path = GetSpecialPath(SpecialPath::BinDirectory);
#else
// FIXME: hard-coded paths
if (IsSharedSetup())
{
path = "/usr/local/bin";
path = GetConfigValue(MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY, MIKTEX_SYSTEM_LINK_TARGET_DIR).GetString();
}
else
{
path = GetHomeDirectory() / "bin";
path = Expand(GetConfigValue(MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY, MIKTEX_USER_LINK_TARGET_DIR).GetString(), { ExpandOption::PathPatterns }, nullptr);
}
#endif
break;
Expand Down
6 changes: 3 additions & 3 deletions Libraries/MiKTeX/Core/Utils/Utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* util.cpp: generi utilities
Copyright (C) 1996-2018 Christian Schenk
Copyright (C) 1996-2019 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -949,10 +949,10 @@ bool Utils::CheckPath()
{
return false;
}
PathName localBinDir = session->GetSpecialPath(SpecialPath::LocalBinDirectory);
PathName linkTargetDirectory = session->GetSpecialPath(SpecialPath::LinkTargetDirectory);
string repairedPath;
bool pathCompetition;
bool pathOkay = !Directory::Exists(localBinDir) || !FixProgramSearchPath(envPath, localBinDir, true, repairedPath, pathCompetition);
bool pathOkay = !Directory::Exists(linkTargetDirectory) || !FixProgramSearchPath(envPath, linkTargetDirectory, true, repairedPath, pathCompetition);
if (!pathOkay)
{
SessionImpl::GetSession()->trace_error->WriteLine("core", T_("Something is wrong with the PATH:"));
Expand Down
6 changes: 3 additions & 3 deletions Libraries/MiKTeX/Core/Utils/unx/unxUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* unxUtil.cpp:
Copyright (C) 1996-2018 Christian Schenk
Copyright (C) 1996-2019 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -136,12 +136,12 @@ bool Utils::CheckPath(bool repair)
return false;
}

PathName localBinDir = session->GetSpecialPath(SpecialPath::LocalBinDirectory);
PathName linkTargetDirectory = session->GetSpecialPath(SpecialPath::LinkTargetDirectory);

string repairedPath;
bool pathCompetition;

bool pathOkay = !Directory::Exists(localBinDir) || !FixProgramSearchPath(envPath, localBinDir, true, repairedPath, pathCompetition);
bool pathOkay = !Directory::Exists(linkTargetDirectory) || !FixProgramSearchPath(envPath, linkTargetDirectory, true, repairedPath, pathCompetition);

bool repaired = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* miktex/Core/ConfigNames.h: -*- C++ -*-
Copyright (C) 2017-2018 Christian Schenk
Copyright (C) 2017-2019 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -35,12 +35,14 @@ constexpr auto MIKTEX_CONFIG_VALUE_ALLOWUNSAFEOUTPUTFILES = "${MIKTEX_CONFIG_VAL
constexpr auto MIKTEX_CONFIG_VALUE_ALTEXTENSIONS = "${MIKTEX_CONFIG_VALUE_ALTEXTENSIONS}";
constexpr auto MIKTEX_CONFIG_VALUE_AUTOADMIN = "${MIKTEX_CONFIG_VALUE_AUTOADMIN}";
constexpr auto MIKTEX_CONFIG_VALUE_AUTOINSTALL = "${MIKTEX_CONFIG_VALUE_AUTOINSTALL}";
constexpr auto MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY = "${MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY}";
constexpr auto MIKTEX_CONFIG_VALUE_CREATEAUXDIRECTORY = "${MIKTEX_CONFIG_VALUE_CREATEAUXDIRECTORY}";
constexpr auto MIKTEX_CONFIG_VALUE_CREATEOUTPUTDIRECTORY = "${MIKTEX_CONFIG_VALUE_CREATEOUTPUTDIRECTORY}";
constexpr auto MIKTEX_CONFIG_VALUE_CSTYLEERRORS = "${MIKTEX_CONFIG_VALUE_CSTYLEERRORS}";
constexpr auto MIKTEX_CONFIG_VALUE_ENVVARS = "${MIKTEX_CONFIG_VALUE_ENVVARS}";
constexpr auto MIKTEX_CONFIG_VALUE_EXTENSIONS = "${MIKTEX_CONFIG_VALUE_EXTENSIONS}";
constexpr auto MIKTEX_CONFIG_VALUE_PATHS = "${MIKTEX_CONFIG_VALUE_PATHS}";
constexpr auto MIKTEX_CONFIG_VALUE_SHELLCOMMANDMODE = "${MIKTEX_CONFIG_VALUE_SHELLCOMMANDMODE}";
constexpr auto MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY = "${MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY}";

#endif
2 changes: 2 additions & 0 deletions Libraries/MiKTeX/Core/include/miktex/Core/Paths.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@

#if defined(MIKTEX_UNIX)
# define MIKTEX_SYSTEM_ETC_FONTS_CONFD_DIR "@MIKTEX_SYSTEM_ETC_FONTS_CONFD_DIR@"
# define MIKTEX_SYSTEM_LINK_TARGET_DIR "@MIKTEX_SYSTEM_LINK_TARGET_DIR@"
# define MIKTEX_SYSTEM_VAR_CACHE_DIR "@MIKTEX_SYSTEM_VAR_CACHE_DIR@"
# define MIKTEX_SYSTEM_VAR_LIB_DIR "@MIKTEX_SYSTEM_VAR_LIB_DIR@"
# define MIKTEX_SYSTEM_VAR_LOG_DIR "@MIKTEX_SYSTEM_VAR_LOG_DIR@"
# define MIKTEX_USER_LINK_TARGET_DIR "@MIKTEX_USER_LINK_TARGET_DIR@"
# define MIKTEX_DIST_DIR "@MIKTEX_DIST_DIR@"
# define MIKTEX_INSTALL_DIR "@MIKTEX_INSTALL_DIR@"
#endif
Expand Down
4 changes: 2 additions & 2 deletions Libraries/MiKTeX/Core/include/miktex/Core/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ enum class SpecialPath
/// The portable mount directory.
PortableMount,

/// The effective directory for symbolic links to MiKTeX binaries.
LocalBinDirectory,
/// The directory in which to create symbolic links to the MiKTeX executables.
LinkTargetDirectory,

/// The effective directory for log files.
LogDirectory,
Expand Down
4 changes: 2 additions & 2 deletions Libraries/MiKTeX/Core/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
## Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA.

set(MIKTEX_COMP_J2000_VERSION 6998)
set(MIKTEX_COMP_INTERFACE_VERSION 11)
set(MIKTEX_COMP_J2000_VERSION 6999)
set(MIKTEX_COMP_INTERFACE_VERSION 12)
10 changes: 9 additions & 1 deletion Libraries/MiKTeX/Setup/SetupService.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SetupService.cpp:
Copyright (C) 2013-2018 Christian Schenk
Copyright (C) 2013-2019 Christian Schenk
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
Expand Down Expand Up @@ -1310,6 +1310,14 @@ void SetupServiceImpl::ConfigureMiKTeX()
{
args.push_back("--user-roots=" + options.Config.userRoots);
}
if (!options.CommonLinkTargetDirectory.Empty())
{
args.push_back(fmt::format("--set-config-value=[{}]{}={}", MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY, options.CommonLinkTargetDirectory));
}
if (!options.UserLinkTargetDirectory.Empty())
{
args.push_back(fmt::format("--set-config-value=[{}]{}={}", MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY, options.UserLinkTargetDirectory));
}
if (!args.empty())
{
RunIniTeXMF(args, true);
Expand Down
8 changes: 7 additions & 1 deletion Libraries/MiKTeX/Setup/include/miktex/Setup/SetupService.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* miktex/Setup/SetupService.h: -*- C++ -*-
Copyright (C) 2013-2018 Christian Schenk
Copyright (C) 2013-2019 Christian Schenk
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
Expand Down Expand Up @@ -158,6 +158,12 @@ struct SetupOptions

public:
std::string PaperSize = "A4";

public:
MiKTeX::Core::PathName CommonLinkTargetDirectory;

public:
MiKTeX::Core::PathName UserLinkTargetDirectory;
};

/// Notification enum class.
Expand Down
4 changes: 2 additions & 2 deletions Libraries/MiKTeX/Setup/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
## Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA.

set(MIKTEX_COMP_J2000_VERSION 6941)
set(MIKTEX_COMP_INTERFACE_VERSION 4)
set(MIKTEX_COMP_J2000_VERSION 7000)
set(MIKTEX_COMP_INTERFACE_VERSION 5)
2 changes: 1 addition & 1 deletion Programs/MiKTeX/Console/Qt/console-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */

#define MIKTEX_COMP_J2000_VERSION 6997
#define MIKTEX_COMP_J2000_VERSION 6999

#include <miktex/Version>
87 changes: 84 additions & 3 deletions Programs/MiKTeX/Console/Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void MainWindow::UpdateUi()
{
ui->groupPathIssue->hide();
}
ui->bindir->setText(QString::fromUtf8(session->GetSpecialPath(SpecialPath::LocalBinDirectory).ToDisplayString().c_str()));
ui->bindir->setText(QString::fromUtf8(session->GetSpecialPath(SpecialPath::LinkTargetDirectory).ToDisplayString().c_str()));
}
if (!IsBackgroundWorkerActive())
{
Expand Down Expand Up @@ -504,7 +504,7 @@ void MainWindow::StartTerminal()
{
try
{
PathName localBinDir = session->GetSpecialPath(SpecialPath::LocalBinDirectory);
PathName localBinDir = session->GetSpecialPath(SpecialPath::LinkTargetDirectory);
string newPath = localBinDir.ToString();
string oldPath;
bool haveOldPath = Utils::GetEnvironmentString("PATH", oldPath);
Expand Down Expand Up @@ -1510,7 +1510,7 @@ void MainWindow::UpdateUiDirectories()
{
rootDirectoryModel->Reload();
ui->treeViewRootDirectories->resizeColumnToContents(0);
ui->lineEditBinDir->setText(QString::fromUtf8(session->GetSpecialPath(SpecialPath::LocalBinDirectory).ToDisplayString().c_str()));
ui->lineEditBinDir->setText(QString::fromUtf8(session->GetSpecialPath(SpecialPath::LinkTargetDirectory).ToDisplayString().c_str()));
ui->lineEditLogDir->setText(QString::fromUtf8(session->GetSpecialPath(SpecialPath::LogDirectory).ToDisplayString().c_str()));
}
}
Expand All @@ -1532,6 +1532,11 @@ void MainWindow::UpdateActionsDirectories()
ui->actionRootDirectoryOpen->setEnabled(selectedCount > 0);
ui->actionRemoveRootDirectory->setEnabled(!IsBackgroundWorkerActive() && !isSetupMode && enableRemove);
ui->actionAddRootDirectory->setEnabled(!IsBackgroundWorkerActive() && !isSetupMode);
#if defined(MIKTEX_WINDOWS)
ui->buttonChangeLinkTargetDirectory->hide();
#else
ui->buttonChangeLinkTargetDirectory->setEnabled(!IsBackgroundWorkerActive() && !isSetupMode && (!session->IsSharedSetup() || session->IsAdminMode()));
#endif
}

string tdsDirs[] = {
Expand Down Expand Up @@ -1682,6 +1687,82 @@ void MainWindow::OnContextMenuRootDirectories(const QPoint& pos)
}
}

#if !defined(MIKTEX_WINDOWS)
bool ChangeLinkTargetDirectoryWorker::Run()
{
bool result = false;
try
{
shared_ptr<Session> session = Session::Get();
RunIniTeXMF({ "--remove-links" });
if (session->IsSharedSetup())
{
session->SetConfigValue(MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_COMMONLINKTARGETDIRECTORY, linkTargetDirectory.ToString());
}
else
{
session->SetConfigValue(MIKTEX_CONFIG_SECTION_CORE, MIKTEX_CONFIG_VALUE_USERLINKTARGETDIRECTORY, linkTargetDirectory.ToString());
}
RunIniTeXMF({ "--mklinks" });
result = true;
}
catch (const MiKTeXException& e)
{
this->e = e;
}
catch (const exception& e)
{
this->e = MiKTeXException(e.what());
}
return result;
}
#endif

#if !defined(MIKTEX_WINDOWS)
void MainWindow::ChangeLinkTargetDirectory()
{
try
{
QString currentLinkTargetDirectory = QString::fromUtf8(session->GetSpecialPath(SpecialPath::LinkTargetDirectory).ToDisplayString().c_str());
QString directory = QFileDialog::getExistingDirectory(this, tr("Change Link Target Directory"), currentLinkTargetDirectory);
if (directory.isNull() || directory == currentLinkTargetDirectory)
{
return;
}
QThread* thread = new QThread;
ChangeLinkTargetDirectoryWorker* worker = new ChangeLinkTargetDirectoryWorker(directory.toUtf8().constData());
backgroundWorkers++;
ui->labelBackgroundTask->setText(tr("Changing link target directory..."));
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(Process()));
connect(worker, &ChangeLinkTargetDirectoryWorker::OnFinish, this, [this]() {
ChangeLinkTargetDirectoryWorker* worker = (ChangeLinkTargetDirectoryWorker*)sender();
if (!worker->GetResult())
{
CriticalError(tr("Something went wrong while changing the link target directory."), ((ChangeLinkTargetDirectoryWorker*)sender())->GetMiKTeXException());
}
backgroundWorkers--;
UpdateUi();
UpdateActions();
worker->deleteLater();
});
connect(worker, SIGNAL(OnFinish()), thread, SLOT(quit()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
UpdateUi();
UpdateActions();
thread->start();
}
catch (const MiKTeXException& e)
{
CriticalError(e);
}
catch (const exception& e)
{
CriticalError(e);
}
}
#endif

void MainWindow::SetupUiFormats()
{
formatModel = new FormatTableModel(this);
Expand Down
Loading

0 comments on commit d590361

Please sign in to comment.