Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research/windows uniciode paths #8831

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/command/render/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import { kJatsSubarticle } from "../../format/jats/format-jats-types.ts";
import { shortUuid } from "../../core/uuid.ts";
import { isServerShinyPython } from "../../core/render.ts";
import { pythonExec } from "../../core/jupyter/exec.ts";
import { encode as base64Encode } from "encoding/base64.ts";

const kQuartoParams = "quarto-params";

Expand Down Expand Up @@ -682,7 +683,7 @@ function initFilterParams(dependenciesFile: string) {
Deno.env.set("QUARTO_WIN_CODEPAGE", value);
}
}
Deno.env.set("QUARTO_FILTER_DEPENDENCY_FILE", dependenciesFile);
Deno.env.set("QUARTO_FILTER_DEPENDENCY_FILE", base64Encode(dependenciesFile));
return params;
}

Expand Down
42 changes: 25 additions & 17 deletions src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/
import { dirname } from "path/mod.ts";
import { basename, dirname } from "path/mod.ts";
import { existsSync } from "fs/mod.ts";
import { isWindows } from "./platform.ts";
import { execProcess } from "./process.ts";
Expand All @@ -16,22 +16,30 @@ export function unzip(file: string) {
if (file.endsWith("zip")) {
// It's a zip file
if (isWindows()) {
const args = [
"-Command",
`"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${file}', '${dir}'); }"`,
];
return safeWindowsExec(
"powershell",
args,
(cmd: string[]) => {
return execProcess(
{
cmd: cmd,
stdout: "piped",
},
);
},
);
const filename = basename(file);
const current = Deno.cwd();
try {
Deno.chdir(dir);
const args = [
"-Command",
`"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${filename}', '.'); }"`,
];

return safeWindowsExec(
"powershell",
args,
(cmd: string[]) => {
return execProcess(
{
cmd: cmd,
stdout: "piped",
},
);
},
);
} finally {
Deno.chdir(current);
}
} else {
// Use the built in unzip command
return execProcess(
Expand Down
2 changes: 1 addition & 1 deletion src/resources/filters/modules/license.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- restructured into the standard license
-- format

local constants = require("./constants")
local constants = require("modules/constants")

local function ccLicenseUrl(type, lang, version)
local langStr = 'en'
Expand Down
21 changes: 12 additions & 9 deletions src/resources/pandoc/datadir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ local function modify_lua_functions(all_compressed_mappings)

end

modify_lua_functions{
local convert_from_utf8 = modify_lua_functions{

-- Unicode to Windows ANSI codepage mappings (compressed and protected by a checksum)

Expand Down Expand Up @@ -1390,12 +1390,13 @@ local function resolve_relative_path(path)
resolved[#resolved + 1] = segment
end
end
return table.concat(resolved, pandoc.path.separator)
local result = table.concat(resolved, pandoc.path.separator)
return result
end

-- Add modules base path to package.path so we can require('modules/...') from
-- any path
package.path = package.path .. ';' .. pandoc.path.normalize(PANDOC_STATE.user_data_dir .. '/../../filters/?.lua')
package.path = package.path .. ';' .. convert_from_utf8(pandoc.path.normalize(PANDOC_STATE.user_data_dir .. '/../../filters/?.lua'))

-- patch require to look in current scriptDirs as well as supporting
-- relative requires
Expand All @@ -1417,9 +1418,10 @@ function require(modname)
-- This strategy is not going to work in general, in the presence of symlinks
-- and other things that can make two paths resolve to the same file. But
-- it's good enough for our purposes.
modname = modname:gsub("/", pandoc.path.separator)
if modname:sub(1, 1) == "." then
local calling_file = debug.getinfo(2, "S").source:sub(2, -1)
local calling_dir = pandoc.path.directory(calling_file)
local calling_dir = calling_file .. pandoc.path.separator .. ".." -- pandoc.path.directory(calling_file)
if calling_dir == "." then
-- resolve to current working directory
calling_dir = scriptDir()
Expand All @@ -1428,18 +1430,19 @@ function require(modname)
-- last-ditch effort, use the current working directory
calling_dir = pandoc.system.get_working_directory()
end
local resolved_path = resolve_relative_path(pandoc.path.normalize(pandoc.path.join({calling_dir, modname})))
return require(resolved_path)
local resolved_path = resolve_relative_path(calling_dir ..pandoc.path.separator .. modname)
modname = resolved_path
-- return require(resolved_path)
end
local old_path = package.path
local new_path = package.path
local dirs = scriptDirs()
for i, v in ipairs(dirs) do
new_path = new_path .. ';' .. pandoc.path.join({v, '?.lua'})
new_path = new_path .. ';' .. convert_from_utf8(v):gsub("/", "\\") .. pandoc.path.separator .. '?.lua'
end

package.path = new_path
local mod = orig_require(modname)
local mod = orig_require(modname:gsub("/", "\\"))
package.path = old_path
return mod
end
Expand Down Expand Up @@ -1490,7 +1493,7 @@ local function dependenciesFile()
if dependenciesFile == nil then
error('Missing expected dependency file environment variable QUARTO_FILTER_DEPENDENCY_FILE')
else
return pandoc.utils.stringify(dependenciesFile)
return quarto.base64.decode(dependenciesFile)
end
end

Expand Down
Loading