mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 10:39:18 +02:00
chore(deps): bump github.com/moby/buildkit from 0.12.5 to 0.13.0 (#3072)
Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.12.5 to 0.13.0. - [Release notes](https://github.com/moby/buildkit/releases) - [Commits](https://github.com/moby/buildkit/compare/v0.12.5...v0.13.0) --- updated-dependencies: - dependency-name: github.com/moby/buildkit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
+220
-2
@@ -1,66 +1,284 @@
|
||||
# This file lists all individuals having contributed content to the repository.
|
||||
# For how it is generated, see `scripts/generate-authors.sh`.
|
||||
# For how it is generated, see hack/dockerfiles/authors.Dockerfile.
|
||||
|
||||
a-palchikov <deemok@gmail.com>
|
||||
Aaron L. Xu <likexu@harmonycloud.cn>
|
||||
Aaron Lehmann <aaron.lehmann@docker.com>
|
||||
Aaron Lehmann <alehmann@netflix.com>
|
||||
Abdur Rehman <abdur_rehman@mentor.com>
|
||||
Addam Hardy <addam.hardy@gmail.com>
|
||||
Adrian Plata <adrian.plata@docker.com>
|
||||
Aidan Hobson Sayers <aidanhs@cantab.net>
|
||||
Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
|
||||
Alan Fregtman <941331+darkvertex@users.noreply.github.com>
|
||||
Alex Couture-Beil <alex@earthly.dev>
|
||||
Alex Mayer <amayer5125@gmail.com>
|
||||
Alex Suraci <suraci.alex@gmail.com>
|
||||
Alexander Morozov <lk4d4@docker.com>
|
||||
Alexis Murzeau <amubtdx@gmail.com>
|
||||
Alice Frosi <afrosi@de.ibm.com>
|
||||
Allen Sun <allen.sun@daocloud.io>
|
||||
Amen Belayneh <amenbelayneh@gmail.com>
|
||||
Anca Iordache <anca.iordache@docker.com>
|
||||
Anda Xu <anda.xu@docker.com>
|
||||
Anders F Björklund <anders.f.bjorklund@gmail.com>
|
||||
Andrea Bolognani <abologna@redhat.com>
|
||||
Andrea Luzzardi <aluzzardi@gmail.com>
|
||||
Andrew Chang <chang331006@gmail.com>
|
||||
Andrey Smirnov <smirnov.andrey@gmail.com>
|
||||
Andy Alt <andy5995@users.noreply.github.com>
|
||||
Andy Caldwell <andrew.caldwell@metaswitch.com>
|
||||
Ankush Agarwal <ankushagarwal11@gmail.com>
|
||||
Anthony Sottile <asottile@umich.edu>
|
||||
Anurag Goel <anurag@render.com>
|
||||
Anusha Ragunathan <anusha@docker.com>
|
||||
Arnaud Bailly <arnaud.oqube@gmail.com>
|
||||
Avi Deitcher <avi@deitcher.net>
|
||||
Bastiaan Bakker <bbakker@xebia.com>
|
||||
Ben Longo <benlongo9807@gmail.com>
|
||||
Bertrand Paquet <bertrand.paquet@gmail.com>
|
||||
Bin Liu <liubin0329@gmail.com>
|
||||
Brandon Mitchell <git@bmitch.net>
|
||||
Brian Goff <cpuguy83@gmail.com>
|
||||
Ce Gao <ce.gao@outlook.com>
|
||||
Chaerim Yeo <yeochaerim@gmail.com>
|
||||
Changwei Ge <gechangwei@bytedance.com>
|
||||
Chanhun Jeong <chanhun.jeong@navercorp.com>
|
||||
ChaosGramer <ChaosGramer@users.noreply.github.com>
|
||||
Charles Chan <charleswhchan@users.noreply.github.com>
|
||||
Charles Korn <me@charleskorn.com>
|
||||
Charles Law <claw@conduce.com>
|
||||
Chenbin <chen.bin11@zte.com.cn>
|
||||
Chris Goller <goller@gmail.com>
|
||||
Chris McKinnel <chrismckinnel@gmail.com>
|
||||
Christian Höltje <docwhat@gerf.org>
|
||||
Christian Weichel <chris@gitpod.io>
|
||||
Ciro S. Costa <cscosta@pivotal.io>
|
||||
Claudiu Belu <cbelu@cloudbasesolutions.com>
|
||||
Colin Chartier <colin.n.chartier@gmail.com>
|
||||
Corey Larson <corey@earthly.dev>
|
||||
Cory Bennett <cbennett@netflix.com>
|
||||
Cory Snider <csnider@mirantis.com>
|
||||
coryb <cbennett@netflix.com>
|
||||
CrazyMax <github@crazymax.dev>
|
||||
Csaba Apagyi <csaba.apagyi@gmail.com>
|
||||
Dan Duvall <dduvall@wikimedia.org>
|
||||
Daniel Cassidy <mail@danielcassidy.me.uk>
|
||||
Daniel Nephin <dnephin@gmail.com>
|
||||
Darren Shepherd <darren@rancher.com>
|
||||
Dave Chen <dave.chen@arm.com>
|
||||
Dave Henderson <dhenderson@gmail.com>
|
||||
Dave Tucker <dt@docker.com>
|
||||
David Calavera <david.calavera@gmail.com>
|
||||
David Dooling <dooling@gmail.com>
|
||||
David Gageot <david.gageot@docker.com>
|
||||
David Karlsson <david.karlsson@docker.com>
|
||||
Davis Schirmer <djds@bghost.xyz>
|
||||
Dennis Chen <dennis.chen@arm.com>
|
||||
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
|
||||
Derek McGowan <derek@mcgstyle.net>
|
||||
Dharmit Shah <shahdharmit@gmail.com>
|
||||
Ding Fei <dingfei@stars.org.cn>
|
||||
dito <itodaisuke00@gmail.com>
|
||||
Doug Davis <dug@us.ibm.com>
|
||||
Edgar Lee <edgarl@netflix.com>
|
||||
Edgar Lee <edgarhinshunlee@gmail.com>
|
||||
Eli Uriegas <eli.uriegas@docker.com>
|
||||
Elias Faxö <elias.faxo@tre.se>
|
||||
Eng Zer Jun <engzerjun@gmail.com>
|
||||
Eric Engestrom <eric@engestrom.ch>
|
||||
Erik Sipsma <erik@sipsma.dev>
|
||||
eyherabh <hugogabriel.eyherabide@gmail.com>
|
||||
f0 <f0@users.noreply.github.com>
|
||||
Fernando Miguel <github@FernandoMiguel.net>
|
||||
Fiona Klute <fiona.klute@gmx.de>
|
||||
Foysal Iqbal <foysal.iqbal.fb@gmail.com>
|
||||
Fred Cox <mcfedr@gmail.com>
|
||||
Frieder Bluemle <frieder.bluemle@gmail.com>
|
||||
Gabriel <samfiragabriel@gmail.com>
|
||||
Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
|
||||
Gaetan de Villele <gdevillele@gmail.com>
|
||||
Gahl Saraf <saraf.gahl@gmail.com>
|
||||
genglu.gl <luzigeng32@163.com>
|
||||
George <george@betterde.com>
|
||||
ggjulio <juligonz@student.42.fr>
|
||||
Govind Rai <raigovind93@gmail.com>
|
||||
Grant Reaber <grant.reaber@gmail.com>
|
||||
Guilhem C <guilhem.charles@gmail.com>
|
||||
Hans van den Bogert <hansbogert@gmail.com>
|
||||
Hao Hu <hao.hu.fr@gmail.com>
|
||||
Hector S <hfsam88@gmail.com>
|
||||
Helen Xie <chenjg@harmonycloud.cn>
|
||||
Himanshu Pandey <hpandey@pivotal.io>
|
||||
Hiromu Nakamura <abctail30@gmail.com>
|
||||
HowJMay <vulxj0j8j8@gmail.com>
|
||||
Hugo Santos <hugo@namespacelabs.com>
|
||||
Ian Campbell <ijc@docker.com>
|
||||
Ilya Dmitrichenko <errordeveloper@gmail.com>
|
||||
Iskander (Alex) Sharipov <quasilyte@gmail.com>
|
||||
Jacob Gillespie <jacobwgillespie@gmail.com>
|
||||
Jacob MacElroy <jacob@okteto.com>
|
||||
Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
|
||||
Jeffrey Huang <jeffreyhuang23@gmail.com>
|
||||
Jesse Rittner <rittneje@gmail.com>
|
||||
Jessica Frazelle <acidburn@microsoft.com>
|
||||
jgeiger <jgeiger@gmail.com>
|
||||
Jitender Kumar <jitender.kumar@intel.com>
|
||||
jlecordier <jeanlecordier@hotmail.fr>
|
||||
joey <zchengjoey@gmail.com>
|
||||
John Howard <jhoward@microsoft.com>
|
||||
John Maguire <jmaguire@duosecurity.com>
|
||||
John Mulhausen <john@docker.com>
|
||||
John Tims <john.k.tims@gmail.com>
|
||||
Jon Zeolla <zeolla@gmail.com>
|
||||
Jonathan Azoff <azoff@users.noreply.github.com>
|
||||
Jonathan Giannuzzi <jonathan@giannuzzi.me>
|
||||
Jonathan Stoppani <jonathan.stoppani@divio.com>
|
||||
Jonny Stoten <jonny.stoten@docker.com>
|
||||
JordanGoasdoue <jordan.goasdoue@dailymotion.com>
|
||||
jroenf <jeroenfranse@gmail.com>
|
||||
Julian Goede <julian.goede@pm.me>
|
||||
Justas Brazauskas <brazauskasjustas@gmail.com>
|
||||
Justin Chadwell <me@jedevc.com>
|
||||
Justin Cormack <justin.cormack@docker.com>
|
||||
Justin Garrison <justin@linux.com>
|
||||
Jörg Franke <359489+NewJorg@users.noreply.github.com>
|
||||
Kang, Matthew <impulsecss@gmail.com>
|
||||
Kees Cook <keescook@chromium.org>
|
||||
Kevin Burke <kev@inburke.com>
|
||||
kevinmeredith <kevin.m.meredith@gmail.com>
|
||||
Kir Kolyshkin <kolyshkin@gmail.com>
|
||||
Kohei Tokunaga <ktokunaga.mail@gmail.com>
|
||||
Koichi Shiraishi <zchee.io@gmail.com>
|
||||
Kris-Mikael Krister <krismikael@protonmail.com>
|
||||
Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
|
||||
Kyle <Kylemit@gmail.com>
|
||||
l00397676 <lujingxiao@huawei.com>
|
||||
Lajos Papp <lalyos@yahoo.com>
|
||||
lalyos <lalyos@yahoo.com>
|
||||
Levi Harrison <levisamuelharrison@gmail.com>
|
||||
liwenqi <vikilwq@zju.edu.cn>
|
||||
lixiaobing10051267 <li.xiaobing1@zte.com.cn>
|
||||
lomot <lomot@qq.com>
|
||||
Lu Jingxiao <lujingxiao@huawei.com>
|
||||
Luca Visentin <luck.visentin@gmail.com>
|
||||
Maciej Kalisz <mdkalish@users.noreply.github.com>
|
||||
Madhav Puri <madhav.puri@gmail.com>
|
||||
Manu Gupta <manugupt1@gmail.com>
|
||||
Marcus Comstedt <marcus@mc.pp.se>
|
||||
Mark Gordon <msg555@gmail.com>
|
||||
Marko Kohtala <marko.kohtala@gmail.com>
|
||||
Mary Anthony <mary@docker.com>
|
||||
masibw <masi19bw@gmail.com>
|
||||
Matias Insaurralde <matias@insaurral.de>
|
||||
Matt Kang <impulsecss@gmail.com>
|
||||
Matt Rickard <mrick@google.com>
|
||||
Maxime Lagresle <maxime@angel.co>
|
||||
Michael Crosby <crosbymichael@gmail.com>
|
||||
Michael Friis <friism@gmail.com>
|
||||
Michael Irwin <mikesir87@gmail.com>
|
||||
Miguel Ángel Jimeno <miguelangel4b@gmail.com>
|
||||
Mihai Borobocea <MihaiBorob@gmail.com>
|
||||
Mike Brown <brownwm@us.ibm.com>
|
||||
mikelinjie <294893458@qq.com>
|
||||
Mikhail Vasin <vasin@cloud-tv.ru>
|
||||
Misty Stanley-Jones <misty@docker.com>
|
||||
Miyachi Katsuya <miyachi_katsuya@r.recruit.co.jp>
|
||||
Morgan Bauer <mbauer@us.ibm.com>
|
||||
Morlay <morlay.null@gmail.com>
|
||||
msg <msg@clinc.com>
|
||||
Nao YONASHIRO <yonashiro@r.recruit.co.jp>
|
||||
Natasha Jarus <linuxmercedes@gmail.com>
|
||||
Nathan Sullivan <nathan@nightsys.net>
|
||||
Nick Miyake <nmiyake@users.noreply.github.com>
|
||||
Nick Santos <nick.santos@docker.com>
|
||||
Nikhil Pandeti <nikhil.pandeti@utexas.edu>
|
||||
Noel Georgi <18496730+frezbo@users.noreply.github.com>
|
||||
Oliver Bristow <oliver.bristow@project-tracr.com>
|
||||
Omer Duchovne <79370724+od-cyera@users.noreply.github.com>
|
||||
Omer Mizrahi <ommizrah@microsoft.com>
|
||||
Ondrej Fabry <ofabry@cisco.com>
|
||||
Otto Kekäläinen <otto@seravo.fi>
|
||||
Pablo Chico de Guzman <pchico83@gmail.com>
|
||||
Patrick Hemmer <patrick.hemmer@gmail.com>
|
||||
Patrick Lang <plang@microsoft.com>
|
||||
Patrick Van Stee <patrick@vanstee.me>
|
||||
Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
|
||||
Paweł Gronowski <pawel.gronowski@docker.com>
|
||||
Peter Dave Hello <hsu@peterdavehello.org>
|
||||
Petr Fedchenkov <giggsoff@gmail.com>
|
||||
Phil Estes <estesp@gmail.com>
|
||||
Pierre Fenoll <pierrefenoll@gmail.com>
|
||||
pieterdd <pieterdd@users.noreply.github.com>
|
||||
Pranav Pandit <pranavp@microsoft.com>
|
||||
Pratik Raj <rajpratik71@gmail.com>
|
||||
Prayag Verma <prayag.verma@gmail.com>
|
||||
Qiang Huang <h.huangqiang@huawei.com>
|
||||
Remy Suen <remy.suen@gmail.com>
|
||||
Ri Xu <xuri.me@gmail.com>
|
||||
Rob Taylor <rob@shape.build>
|
||||
Robert Estelle <robertestelle@gmail.com>
|
||||
Rubens Figueiredo <r.figueiredo.52@gmail.com>
|
||||
Sam Whited <sam@samwhited.com>
|
||||
Sascha Schwarze <schwarzs@de.ibm.com>
|
||||
Sean P. Kane <spkane00@gmail.com>
|
||||
Sebastiaan van Stijn <github@gone.nl>
|
||||
Seiya Miyata <odradek38@gmail.com>
|
||||
Serhat Gülçiçek <serhat25@gmail.com>
|
||||
Sertac Ozercan <sozercan@gmail.com>
|
||||
Shev Yan <yandong_8212@163.com>
|
||||
Shijiang Wei <mountkin@gmail.com>
|
||||
Shingo Omura <everpeace@gmail.com>
|
||||
Shiwei Zhang <shizh@microsoft.com>
|
||||
Siebe Schaap <siebe@digibites.nl>
|
||||
Silvin Lubecki <31478878+silvin-lubecki@users.noreply.github.com>
|
||||
Simon Ferquel <simon.ferquel@docker.com>
|
||||
Slava Semushin <semushin@redhat.com>
|
||||
Solomon Hykes <sh.github.6811@hykes.org>
|
||||
squeegels <1674195+squeegels@users.noreply.github.com>
|
||||
Stefan Scherer <stefan.scherer@docker.com>
|
||||
Stefan Weil <sw@weilnetz.de>
|
||||
StefanSchoof <Stefan.Schoof@direkt-gruppe.de>
|
||||
Stepan Blyshchak <stepanblischak@gmail.com>
|
||||
Steve Lohr <schdief.law@gmail.com>
|
||||
sunchunming <sunchunming1@jd.com>
|
||||
Sven Dowideit <SvenDowideit@home.org.au>
|
||||
Takuya Noguchi <takninnovationresearch@gmail.com>
|
||||
Thomas Leonard <thomas.leonard@docker.com>
|
||||
Thomas Riccardi <riccardi@systran.fr>
|
||||
Thomas Shaw <tomwillfixit@users.noreply.github.com>
|
||||
Tianon Gravi <admwiggin@gmail.com>
|
||||
Tibor Vass <tibor@docker.com>
|
||||
Tiffany Jernigan <tiffany.f.j@gmail.com>
|
||||
Tim Waugh <twaugh@redhat.com>
|
||||
Tim Wraight <tim.wraight@tangentlabs.co.uk>
|
||||
Tino Rusch <tino.rusch@gmail.com>
|
||||
Tobias Klauser <tklauser@distanz.ch>
|
||||
Tomas Tomecek <ttomecek@redhat.com>
|
||||
Tomasz Kopczynski <tomek@kopczynski.net.pl>
|
||||
Tomohiro Kusumoto <zabio1192@gmail.com>
|
||||
Troels Liebe Bentsen <tlb@nversion.dk>
|
||||
Tõnis Tiigi <tonistiigi@gmail.com>
|
||||
Valentin Lorentz <progval+git@progval.net>
|
||||
Vasek - Tom C <tom.chauveau@epitech.eu>
|
||||
Victor Vieux <victorvieux@gmail.com>
|
||||
Victoria Bialas <victoria.bialas@docker.com>
|
||||
Vincent Demeester <vincent.demeester@docker.com>
|
||||
Vlad A. Ionescu <vladaionescu@users.noreply.github.com>
|
||||
Vladislav Ivanov <vlad@ivanov.email>
|
||||
Wang Yumu <37442693@qq.com>
|
||||
Wei Fu <fuweid89@gmail.com>
|
||||
Wei Zhang <kweizh@gmail.com>
|
||||
wingkwong <wingkwong.code@gmail.com>
|
||||
Xiaofan Zhang <xiaofan.zhang@clinc.com>
|
||||
Ximo Guanter <ximo.guanter@gmail.com>
|
||||
Yamazaki Masashi <masi19bw@gmail.com>
|
||||
Yan Song <imeoer@linux.alibaba.com>
|
||||
Yong Tang <yong.tang.github@outlook.com>
|
||||
Yuichiro Kaneko <spiketeika@gmail.com>
|
||||
Yurii Rashkovskii <yrashk@gmail.com>
|
||||
Zach Badgett <zach.badgett@gmail.com>
|
||||
zhangwenlong <zhangwenlong8911@163.com>
|
||||
Ziv Tsarfati <digger18@gmail.com>
|
||||
岁丰 <genglu.gl@antfin.com>
|
||||
沈陵 <shenling.yyb@alibaba-inc.com>
|
||||
郑泽宇 <perhapszzy@sina.com>
|
||||
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
package dockerignore
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ReadAll reads a .dockerignore file and returns the list of file patterns
|
||||
// to ignore. Note this will trim whitespace from each line as well
|
||||
// as use GO's "clean" func to get the shortest/cleanest path for each.
|
||||
func ReadAll(reader io.Reader) ([]string, error) {
|
||||
if reader == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(reader)
|
||||
var excludes []string
|
||||
currentLine := 0
|
||||
|
||||
utf8bom := []byte{0xEF, 0xBB, 0xBF}
|
||||
for scanner.Scan() {
|
||||
scannedBytes := scanner.Bytes()
|
||||
// We trim UTF8 BOM
|
||||
if currentLine == 0 {
|
||||
scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom)
|
||||
}
|
||||
pattern := string(scannedBytes)
|
||||
currentLine++
|
||||
// Lines starting with # (comments) are ignored before processing
|
||||
if strings.HasPrefix(pattern, "#") {
|
||||
continue
|
||||
}
|
||||
pattern = strings.TrimSpace(pattern)
|
||||
if pattern == "" {
|
||||
continue
|
||||
}
|
||||
// normalize absolute paths to paths relative to the context
|
||||
// (taking care of '!' prefix)
|
||||
invert := pattern[0] == '!'
|
||||
if invert {
|
||||
pattern = strings.TrimSpace(pattern[1:])
|
||||
}
|
||||
if len(pattern) > 0 {
|
||||
pattern = filepath.Clean(pattern)
|
||||
pattern = filepath.ToSlash(pattern)
|
||||
if len(pattern) > 1 && pattern[0] == '/' {
|
||||
pattern = pattern[1:]
|
||||
}
|
||||
}
|
||||
if invert {
|
||||
pattern = "!" + pattern
|
||||
}
|
||||
|
||||
excludes = append(excludes, pattern)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, errors.Wrap(err, "error reading .dockerignore")
|
||||
}
|
||||
return excludes, nil
|
||||
}
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
package dockerignore
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/moby/patternmatcher/ignorefile"
|
||||
)
|
||||
|
||||
// ReadAll is an alias for [ignorefile.ReadAll].
|
||||
//
|
||||
// Deprecated: use [ignorefile.ReadAll] instead.
|
||||
func ReadAll(reader io.Reader) ([]string, error) {
|
||||
return ignorefile.ReadAll(reader)
|
||||
}
|
||||
+12
-9
@@ -239,11 +239,12 @@ func (s *SourcesAndDest) ExpandRaw(expander SingleWordExpander) error {
|
||||
type AddCommand struct {
|
||||
withNameAndCode
|
||||
SourcesAndDest
|
||||
Chown string
|
||||
Chmod string
|
||||
Link bool
|
||||
KeepGitDir bool // whether to keep .git dir, only meaningful for git sources
|
||||
Checksum string
|
||||
Chown string
|
||||
Chmod string
|
||||
Link bool
|
||||
ExcludePatterns []string
|
||||
KeepGitDir bool // whether to keep .git dir, only meaningful for git sources
|
||||
Checksum string
|
||||
}
|
||||
|
||||
func (c *AddCommand) Expand(expander SingleWordExpander) error {
|
||||
@@ -270,10 +271,12 @@ func (c *AddCommand) Expand(expander SingleWordExpander) error {
|
||||
type CopyCommand struct {
|
||||
withNameAndCode
|
||||
SourcesAndDest
|
||||
From string
|
||||
Chown string
|
||||
Chmod string
|
||||
Link bool
|
||||
From string
|
||||
Chown string
|
||||
Chmod string
|
||||
Link bool
|
||||
ExcludePatterns []string
|
||||
Parents bool // parents preserves directory structure
|
||||
}
|
||||
|
||||
func (c *CopyCommand) Expand(expander SingleWordExpander) error {
|
||||
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
//go:build dfexcludepatterns
|
||||
// +build dfexcludepatterns
|
||||
|
||||
package instructions
|
||||
|
||||
func init() {
|
||||
excludePatternsEnabled = true
|
||||
}
|
||||
+35
@@ -20,6 +20,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var excludePatternsEnabled = false
|
||||
|
||||
type parseRequest struct {
|
||||
command string
|
||||
args []string
|
||||
@@ -34,6 +36,8 @@ type parseRequest struct {
|
||||
var parseRunPreHooks []func(*RunCommand, parseRequest) error
|
||||
var parseRunPostHooks []func(*RunCommand, parseRequest) error
|
||||
|
||||
var parentsEnabled = false
|
||||
|
||||
func nodeArgs(node *parser.Node) []string {
|
||||
result := []string{}
|
||||
for ; node.Next != nil; node = node.Next {
|
||||
@@ -278,10 +282,26 @@ func parseSourcesAndDest(req parseRequest, command string) (*SourcesAndDest, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func stringValuesFromFlagIfPossible(f *Flag) []string {
|
||||
if f == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return f.StringValues
|
||||
}
|
||||
|
||||
func parseAdd(req parseRequest) (*AddCommand, error) {
|
||||
if len(req.args) < 2 {
|
||||
return nil, errNoDestinationArgument("ADD")
|
||||
}
|
||||
|
||||
var flExcludes *Flag
|
||||
|
||||
// silently ignore if not -labs
|
||||
if excludePatternsEnabled {
|
||||
flExcludes = req.flags.AddStrings("exclude")
|
||||
}
|
||||
|
||||
flChown := req.flags.AddString("chown", "")
|
||||
flChmod := req.flags.AddString("chmod", "")
|
||||
flLink := req.flags.AddBool("link", false)
|
||||
@@ -304,6 +324,7 @@ func parseAdd(req parseRequest) (*AddCommand, error) {
|
||||
Link: flLink.Value == "true",
|
||||
KeepGitDir: flKeepGitDir.Value == "true",
|
||||
Checksum: flChecksum.Value,
|
||||
ExcludePatterns: stringValuesFromFlagIfPossible(flExcludes),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -311,10 +332,22 @@ func parseCopy(req parseRequest) (*CopyCommand, error) {
|
||||
if len(req.args) < 2 {
|
||||
return nil, errNoDestinationArgument("COPY")
|
||||
}
|
||||
|
||||
var flExcludes *Flag
|
||||
var flParents *Flag
|
||||
|
||||
if excludePatternsEnabled {
|
||||
flExcludes = req.flags.AddStrings("exclude")
|
||||
}
|
||||
if parentsEnabled {
|
||||
flParents = req.flags.AddBool("parents", false)
|
||||
}
|
||||
|
||||
flChown := req.flags.AddString("chown", "")
|
||||
flFrom := req.flags.AddString("from", "")
|
||||
flChmod := req.flags.AddString("chmod", "")
|
||||
flLink := req.flags.AddBool("link", false)
|
||||
|
||||
if err := req.flags.Parse(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,6 +364,8 @@ func parseCopy(req parseRequest) (*CopyCommand, error) {
|
||||
Chown: flChown.Value,
|
||||
Chmod: flChmod.Value,
|
||||
Link: flLink.Value == "true",
|
||||
Parents: flParents != nil && flParents.Value == "true",
|
||||
ExcludePatterns: stringValuesFromFlagIfPossible(flExcludes),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
//go:build dfparents
|
||||
// +build dfparents
|
||||
|
||||
package instructions
|
||||
|
||||
func init() {
|
||||
parentsEnabled = true
|
||||
}
|
||||
+4
-3
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
// ErrorLocation gives a location in source code that caused the error
|
||||
type ErrorLocation struct {
|
||||
Location []Range
|
||||
Locations [][]Range
|
||||
error
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@ func WithLocation(err error, location []Range) error {
|
||||
}
|
||||
var el *ErrorLocation
|
||||
if errors.As(err, &el) {
|
||||
el.Locations = append(el.Locations, location)
|
||||
return err
|
||||
}
|
||||
return stack.Enable(&ErrorLocation{
|
||||
error: err,
|
||||
Location: location,
|
||||
error: err,
|
||||
Locations: [][]Range{location},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+175
-4
@@ -3,6 +3,7 @@ package shell
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/scanner"
|
||||
"unicode"
|
||||
@@ -100,7 +101,7 @@ type shellWord struct {
|
||||
}
|
||||
|
||||
func (sw *shellWord) process(source string) (string, []string, error) {
|
||||
word, words, err := sw.processStopOn(scanner.EOF)
|
||||
word, words, err := sw.processStopOn(scanner.EOF, sw.rawEscapes)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "failed to process %q", source)
|
||||
}
|
||||
@@ -154,7 +155,7 @@ func (w *wordsStruct) getWords() []string {
|
||||
|
||||
// Process the word, starting at 'pos', and stop when we get to the
|
||||
// end of the word or the 'stopChar' character
|
||||
func (sw *shellWord) processStopOn(stopChar rune) (string, []string, error) {
|
||||
func (sw *shellWord) processStopOn(stopChar rune, rawEscapes bool) (string, []string, error) {
|
||||
var result bytes.Buffer
|
||||
var words wordsStruct
|
||||
|
||||
@@ -166,6 +167,14 @@ func (sw *shellWord) processStopOn(stopChar rune) (string, []string, error) {
|
||||
charFuncMapping['"'] = sw.processDoubleQuote
|
||||
}
|
||||
|
||||
// temporarily set sw.rawEscapes if needed
|
||||
if rawEscapes != sw.rawEscapes {
|
||||
sw.rawEscapes = rawEscapes
|
||||
defer func() {
|
||||
sw.rawEscapes = !rawEscapes
|
||||
}()
|
||||
}
|
||||
|
||||
for sw.scanner.Peek() != scanner.EOF {
|
||||
ch := sw.scanner.Peek()
|
||||
|
||||
@@ -351,8 +360,9 @@ func (sw *shellWord) processDollar() (string, error) {
|
||||
ch = sw.scanner.Next()
|
||||
chs += string(ch)
|
||||
fallthrough
|
||||
case '+', '-', '?':
|
||||
word, _, err := sw.processStopOn('}')
|
||||
case '+', '-', '?', '#', '%':
|
||||
rawEscapes := ch == '#' || ch == '%'
|
||||
word, _, err := sw.processStopOn('}', rawEscapes)
|
||||
if err != nil {
|
||||
if sw.scanner.Peek() == scanner.EOF {
|
||||
return "", errors.New("syntax error: missing '}'")
|
||||
@@ -394,9 +404,60 @@ func (sw *shellWord) processDollar() (string, error) {
|
||||
return "", errors.Errorf("%s: %s", name, message)
|
||||
}
|
||||
return value, nil
|
||||
case '%', '#':
|
||||
// %/# matches the shortest pattern expansion, %%/## the longest
|
||||
greedy := false
|
||||
if word[0] == byte(ch) {
|
||||
greedy = true
|
||||
word = word[1:]
|
||||
}
|
||||
|
||||
if ch == '%' {
|
||||
return trimSuffix(word, value, greedy)
|
||||
}
|
||||
return trimPrefix(word, value, greedy)
|
||||
default:
|
||||
return "", errors.Errorf("unsupported modifier (%s) in substitution", chs)
|
||||
}
|
||||
case '/':
|
||||
replaceAll := sw.scanner.Peek() == '/'
|
||||
if replaceAll {
|
||||
sw.scanner.Next()
|
||||
}
|
||||
|
||||
pattern, _, err := sw.processStopOn('/', true)
|
||||
if err != nil {
|
||||
if sw.scanner.Peek() == scanner.EOF {
|
||||
return "", errors.New("syntax error: missing '/' in ${}")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
replacement, _, err := sw.processStopOn('}', true)
|
||||
if err != nil {
|
||||
if sw.scanner.Peek() == scanner.EOF {
|
||||
return "", errors.New("syntax error: missing '}'")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
value, set := sw.getEnv(name)
|
||||
if sw.skipUnsetEnv && !set {
|
||||
return fmt.Sprintf("${%s/%s/%s}", name, pattern, replacement), nil
|
||||
}
|
||||
|
||||
re, err := convertShellPatternToRegex(pattern, true, false)
|
||||
if err != nil {
|
||||
return "", errors.Errorf("invalid pattern (%s) in substitution: %s", pattern, err)
|
||||
}
|
||||
if replaceAll {
|
||||
value = re.ReplaceAllString(value, replacement)
|
||||
} else {
|
||||
if idx := re.FindStringIndex(value); idx != nil {
|
||||
value = value[0:idx[0]] + replacement + value[idx[1]:]
|
||||
}
|
||||
}
|
||||
return value, nil
|
||||
default:
|
||||
return "", errors.Errorf("unsupported modifier (%s) in substitution", chs)
|
||||
}
|
||||
@@ -472,3 +533,113 @@ func BuildEnvs(env []string) map[string]string {
|
||||
|
||||
return envs
|
||||
}
|
||||
|
||||
// convertShellPatternToRegex converts a shell-like wildcard pattern
|
||||
// (? is a single char, * either the shortest or longest (greedy) string)
|
||||
// to an equivalent regular expression.
|
||||
//
|
||||
// Based on
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
|
||||
// but without the bracket expressions (`[]`)
|
||||
func convertShellPatternToRegex(pattern string, greedy bool, anchored bool) (*regexp.Regexp, error) {
|
||||
var s scanner.Scanner
|
||||
s.Init(strings.NewReader(pattern))
|
||||
var out strings.Builder
|
||||
out.Grow(len(pattern) + 4)
|
||||
|
||||
// match only at the beginning of the string
|
||||
if anchored {
|
||||
out.WriteByte('^')
|
||||
}
|
||||
|
||||
// default: non-greedy wildcards
|
||||
starPattern := ".*?"
|
||||
if greedy {
|
||||
starPattern = ".*"
|
||||
}
|
||||
|
||||
for tok := s.Next(); tok != scanner.EOF; tok = s.Next() {
|
||||
switch tok {
|
||||
case '*':
|
||||
out.WriteString(starPattern)
|
||||
continue
|
||||
case '?':
|
||||
out.WriteByte('.')
|
||||
continue
|
||||
case '\\':
|
||||
// } and / as part of ${} need to be escaped, but the escape isn't part
|
||||
// of the pattern
|
||||
if s.Peek() == '}' || s.Peek() == '/' {
|
||||
continue
|
||||
}
|
||||
out.WriteRune('\\')
|
||||
tok = s.Next()
|
||||
if tok != '*' && tok != '?' && tok != '\\' {
|
||||
return nil, errors.Errorf("invalid escape '\\%c'", tok)
|
||||
}
|
||||
// regex characters that need to be escaped
|
||||
// escaping closing is optional, but done for consistency
|
||||
case '[', ']', '{', '}', '.', '+', '(', ')', '|', '^', '$':
|
||||
out.WriteByte('\\')
|
||||
}
|
||||
out.WriteRune(tok)
|
||||
}
|
||||
return regexp.Compile(out.String())
|
||||
}
|
||||
|
||||
func trimPrefix(word, value string, greedy bool) (string, error) {
|
||||
re, err := convertShellPatternToRegex(word, greedy, true)
|
||||
if err != nil {
|
||||
return "", errors.Errorf("invalid pattern (%s) in substitution: %s", word, err)
|
||||
}
|
||||
|
||||
if idx := re.FindStringIndex(value); idx != nil {
|
||||
value = value[idx[1]:]
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// reverse without avoid reversing escapes, i.e. a\*c -> c\*a
|
||||
func reversePattern(pattern string) string {
|
||||
patternRunes := []rune(pattern)
|
||||
out := make([]rune, len(patternRunes))
|
||||
lastIdx := len(patternRunes) - 1
|
||||
for i := 0; i <= lastIdx; {
|
||||
tok := patternRunes[i]
|
||||
outIdx := lastIdx - i
|
||||
if tok == '\\' && i != lastIdx {
|
||||
out[outIdx-1] = tok
|
||||
// the pattern is taken from a ${var#pattern}, so the last
|
||||
// character can't be an escape character
|
||||
out[outIdx] = patternRunes[i+1]
|
||||
i += 2
|
||||
} else {
|
||||
out[outIdx] = tok
|
||||
i++
|
||||
}
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func reverseString(str string) string {
|
||||
out := []rune(str)
|
||||
outIdx := len(out) - 1
|
||||
for i := 0; i < outIdx; i++ {
|
||||
out[i], out[outIdx] = out[outIdx], out[i]
|
||||
outIdx--
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func trimSuffix(pattern, word string, greedy bool) (string, error) {
|
||||
// regular expressions can't handle finding the shortest rightmost
|
||||
// string so we reverse both search space and pattern to convert it
|
||||
// to a leftmost search in both cases
|
||||
pattern = reversePattern(pattern)
|
||||
word = reverseString(word)
|
||||
str, err := trimPrefix(pattern, word, greedy)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return reverseString(str), nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.30.0
|
||||
// protoc-gen-go v1.31.0
|
||||
// protoc v3.11.4
|
||||
// source: stack.proto
|
||||
|
||||
|
||||
+8
-8
@@ -3,15 +3,15 @@ syntax = "proto3";
|
||||
package stack;
|
||||
|
||||
message Stack {
|
||||
repeated Frame frames = 1;
|
||||
repeated string cmdline = 2;
|
||||
int32 pid = 3;
|
||||
string version = 4;
|
||||
string revision = 5;
|
||||
repeated Frame frames = 1;
|
||||
repeated string cmdline = 2;
|
||||
int32 pid = 3;
|
||||
string version = 4;
|
||||
string revision = 5;
|
||||
}
|
||||
|
||||
message Frame {
|
||||
string Name = 1;
|
||||
string File = 2;
|
||||
int32 Line = 3;
|
||||
string Name = 1;
|
||||
string File = 2;
|
||||
int32 Line = 3;
|
||||
}
|
||||
+43
-7
@@ -5,15 +5,19 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// GetMountsFromReader retrieves a list of mounts from the
|
||||
// reader provided, with an optional filter applied (use nil
|
||||
// for no filter). This can be useful in tests or benchmarks
|
||||
// that provide fake mountinfo data, or when a source other
|
||||
// than /proc/self/mountinfo needs to be read from.
|
||||
// than /proc/thread-self/mountinfo needs to be read from.
|
||||
//
|
||||
// This function is Linux-specific.
|
||||
func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
|
||||
@@ -127,8 +131,40 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func parseMountTable(filter FilterFunc) ([]*Info, error) {
|
||||
f, err := os.Open("/proc/self/mountinfo")
|
||||
var (
|
||||
haveProcThreadSelf bool
|
||||
haveProcThreadSelfOnce sync.Once
|
||||
)
|
||||
|
||||
func parseMountTable(filter FilterFunc) (_ []*Info, err error) {
|
||||
haveProcThreadSelfOnce.Do(func() {
|
||||
_, err := os.Stat("/proc/thread-self/mountinfo")
|
||||
haveProcThreadSelf = err == nil
|
||||
})
|
||||
|
||||
// We need to lock ourselves to the current OS thread in order to make sure
|
||||
// that the thread referenced by /proc/thread-self stays alive until we
|
||||
// finish parsing the file.
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
var f *os.File
|
||||
if haveProcThreadSelf {
|
||||
f, err = os.Open("/proc/thread-self/mountinfo")
|
||||
} else {
|
||||
// On pre-3.17 kernels (such as CentOS 7), we don't have
|
||||
// /proc/thread-self/ so we need to manually construct
|
||||
// /proc/self/task/<tid>/ as a fallback.
|
||||
f, err = os.Open("/proc/self/task/" + strconv.Itoa(unix.Gettid()) + "/mountinfo")
|
||||
if os.IsNotExist(err) {
|
||||
// If /proc/self/task/... failed, it means that our active pid
|
||||
// namespace doesn't match the pid namespace of the /proc mount. In
|
||||
// this case we just have to make do with /proc/self, since there
|
||||
// is no other way of figuring out our tid in a parent pid
|
||||
// namespace on pre-3.17 kernels.
|
||||
f, err = os.Open("/proc/self/mountinfo")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -158,10 +194,10 @@ func PidMountInfo(pid int) ([]*Info, error) {
|
||||
// A few specific characters in mountinfo path entries (root and mountpoint)
|
||||
// are escaped using a backslash followed by a character's ascii code in octal.
|
||||
//
|
||||
// space -- as \040
|
||||
// tab (aka \t) -- as \011
|
||||
// newline (aka \n) -- as \012
|
||||
// backslash (aka \\) -- as \134
|
||||
// space -- as \040
|
||||
// tab (aka \t) -- as \011
|
||||
// newline (aka \n) -- as \012
|
||||
// backslash (aka \\) -- as \134
|
||||
//
|
||||
// This function converts path from mountinfo back, i.e. it unescapes the above sequences.
|
||||
func unescape(path string) (string, error) {
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Package term provides structures and helper functions to work with
|
||||
// terminal (state, sizes).
|
||||
package term
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package term
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func tcget(fd uintptr) (*Termios, error) {
|
||||
p, err := unix.IoctlGetTermios(int(fd), getTermios)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func tcset(fd uintptr, p *Termios) error {
|
||||
return unix.IoctlSetTermios(int(fd), setTermios, p)
|
||||
}
|
||||
+43
-58
@@ -1,100 +1,85 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
// Package term provides structures and helper functions to work with
|
||||
// terminal (state, sizes).
|
||||
package term
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
import "io"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// ErrInvalidState is returned if the state of the terminal is invalid.
|
||||
var ErrInvalidState = errors.New("Invalid terminal state")
|
||||
|
||||
// State represents the state of the terminal.
|
||||
type State struct {
|
||||
termios Termios
|
||||
}
|
||||
// State holds the platform-specific state / console mode for the terminal.
|
||||
type State terminalState
|
||||
|
||||
// Winsize represents the size of the terminal window.
|
||||
type Winsize struct {
|
||||
Height uint16
|
||||
Width uint16
|
||||
x uint16
|
||||
y uint16
|
||||
|
||||
// Only used on Unix
|
||||
x uint16
|
||||
y uint16
|
||||
}
|
||||
|
||||
// StdStreams returns the standard streams (stdin, stdout, stderr).
|
||||
//
|
||||
// On Windows, it attempts to turn on VT handling on all std handles if
|
||||
// supported, or falls back to terminal emulation. On Unix, this returns
|
||||
// the standard [os.Stdin], [os.Stdout] and [os.Stderr].
|
||||
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
return os.Stdin, os.Stdout, os.Stderr
|
||||
return stdStreams()
|
||||
}
|
||||
|
||||
// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal.
|
||||
func GetFdInfo(in interface{}) (uintptr, bool) {
|
||||
var inFd uintptr
|
||||
var isTerminalIn bool
|
||||
if file, ok := in.(*os.File); ok {
|
||||
inFd = file.Fd()
|
||||
isTerminalIn = IsTerminal(inFd)
|
||||
}
|
||||
return inFd, isTerminalIn
|
||||
func GetFdInfo(in interface{}) (fd uintptr, isTerminal bool) {
|
||||
return getFdInfo(in)
|
||||
}
|
||||
|
||||
// GetWinsize returns the window size based on the specified file descriptor.
|
||||
func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
return getWinsize(fd)
|
||||
}
|
||||
|
||||
// SetWinsize tries to set the specified window size for the specified file
|
||||
// descriptor. It is only implemented on Unix, and returns an error on Windows.
|
||||
func SetWinsize(fd uintptr, ws *Winsize) error {
|
||||
return setWinsize(fd, ws)
|
||||
}
|
||||
|
||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
_, err := tcget(fd)
|
||||
return err == nil
|
||||
return isTerminal(fd)
|
||||
}
|
||||
|
||||
// RestoreTerminal restores the terminal connected to the given file descriptor
|
||||
// to a previous state.
|
||||
func RestoreTerminal(fd uintptr, state *State) error {
|
||||
if state == nil {
|
||||
return ErrInvalidState
|
||||
}
|
||||
return tcset(fd, &state.termios)
|
||||
return restoreTerminal(fd, state)
|
||||
}
|
||||
|
||||
// SaveState saves the state of the terminal connected to the given file descriptor.
|
||||
func SaveState(fd uintptr) (*State, error) {
|
||||
termios, err := tcget(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &State{termios: *termios}, nil
|
||||
return saveState(fd)
|
||||
}
|
||||
|
||||
// DisableEcho applies the specified state to the terminal connected to the file
|
||||
// descriptor, with echo disabled.
|
||||
func DisableEcho(fd uintptr, state *State) error {
|
||||
newState := state.termios
|
||||
newState.Lflag &^= unix.ECHO
|
||||
|
||||
if err := tcset(fd, &newState); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return disableEcho(fd, state)
|
||||
}
|
||||
|
||||
// SetRawTerminal puts the terminal connected to the given file descriptor into
|
||||
// raw mode and returns the previous state. On UNIX, this puts both the input
|
||||
// and output into raw mode. On Windows, it only puts the input into raw mode.
|
||||
func SetRawTerminal(fd uintptr) (*State, error) {
|
||||
oldState, err := MakeRaw(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return oldState, err
|
||||
// raw mode and returns the previous state. On UNIX, this is the equivalent of
|
||||
// [MakeRaw], and puts both the input and output into raw mode. On Windows, it
|
||||
// only puts the input into raw mode.
|
||||
func SetRawTerminal(fd uintptr) (previousState *State, err error) {
|
||||
return setRawTerminal(fd)
|
||||
}
|
||||
|
||||
// SetRawTerminalOutput puts the output of terminal connected to the given file
|
||||
// descriptor into raw mode. On UNIX, this does nothing and returns nil for the
|
||||
// state. On Windows, it disables LF -> CRLF translation.
|
||||
func SetRawTerminalOutput(fd uintptr) (*State, error) {
|
||||
return nil, nil
|
||||
func SetRawTerminalOutput(fd uintptr) (previousState *State, err error) {
|
||||
return setRawTerminalOutput(fd)
|
||||
}
|
||||
|
||||
// MakeRaw puts the terminal (Windows Console) connected to the
|
||||
// given file descriptor into raw mode and returns the previous state of
|
||||
// the terminal so that it can be restored.
|
||||
func MakeRaw(fd uintptr) (previousState *State, err error) {
|
||||
return makeRaw(fd)
|
||||
}
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package term
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// ErrInvalidState is returned if the state of the terminal is invalid.
|
||||
//
|
||||
// Deprecated: ErrInvalidState is no longer used.
|
||||
var ErrInvalidState = errors.New("Invalid terminal state")
|
||||
|
||||
// terminalState holds the platform-specific state / console mode for the terminal.
|
||||
type terminalState struct {
|
||||
termios unix.Termios
|
||||
}
|
||||
|
||||
func stdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
return os.Stdin, os.Stdout, os.Stderr
|
||||
}
|
||||
|
||||
func getFdInfo(in interface{}) (uintptr, bool) {
|
||||
var inFd uintptr
|
||||
var isTerminalIn bool
|
||||
if file, ok := in.(*os.File); ok {
|
||||
inFd = file.Fd()
|
||||
isTerminalIn = isTerminal(inFd)
|
||||
}
|
||||
return inFd, isTerminalIn
|
||||
}
|
||||
|
||||
func getWinsize(fd uintptr) (*Winsize, error) {
|
||||
uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
|
||||
ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
|
||||
return ws, err
|
||||
}
|
||||
|
||||
func setWinsize(fd uintptr, ws *Winsize) error {
|
||||
return unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, &unix.Winsize{
|
||||
Row: ws.Height,
|
||||
Col: ws.Width,
|
||||
Xpixel: ws.x,
|
||||
Ypixel: ws.y,
|
||||
})
|
||||
}
|
||||
|
||||
func isTerminal(fd uintptr) bool {
|
||||
_, err := tcget(fd)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func restoreTerminal(fd uintptr, state *State) error {
|
||||
if state == nil {
|
||||
return errors.New("invalid terminal state")
|
||||
}
|
||||
return tcset(fd, &state.termios)
|
||||
}
|
||||
|
||||
func saveState(fd uintptr) (*State, error) {
|
||||
termios, err := tcget(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &State{termios: *termios}, nil
|
||||
}
|
||||
|
||||
func disableEcho(fd uintptr, state *State) error {
|
||||
newState := state.termios
|
||||
newState.Lflag &^= unix.ECHO
|
||||
|
||||
return tcset(fd, &newState)
|
||||
}
|
||||
|
||||
func setRawTerminal(fd uintptr) (*State, error) {
|
||||
return makeRaw(fd)
|
||||
}
|
||||
|
||||
func setRawTerminalOutput(fd uintptr) (*State, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func tcget(fd uintptr) (*unix.Termios, error) {
|
||||
p, err := unix.IoctlGetTermios(int(fd), getTermios)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func tcset(fd uintptr, p *unix.Termios) error {
|
||||
return unix.IoctlSetTermios(int(fd), setTermios, p)
|
||||
}
|
||||
+24
-75
@@ -1,6 +1,7 @@
|
||||
package term
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -9,22 +10,15 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// State holds the console mode for the terminal.
|
||||
type State struct {
|
||||
// terminalState holds the platform-specific state / console mode for the terminal.
|
||||
type terminalState struct {
|
||||
mode uint32
|
||||
}
|
||||
|
||||
// Winsize is used for window size.
|
||||
type Winsize struct {
|
||||
Height uint16
|
||||
Width uint16
|
||||
}
|
||||
|
||||
// vtInputSupported is true if winterm.ENABLE_VIRTUAL_TERMINAL_INPUT is supported by the console
|
||||
var vtInputSupported bool
|
||||
|
||||
// StdStreams returns the standard streams (stdin, stdout, stderr).
|
||||
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
func stdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
// Turn on VT handling on all std handles, if possible. This might
|
||||
// fail, in which case we will fall back to terminal emulation.
|
||||
var (
|
||||
@@ -87,16 +81,14 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||
stdErr = os.Stderr
|
||||
}
|
||||
|
||||
return
|
||||
return stdIn, stdOut, stdErr
|
||||
}
|
||||
|
||||
// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal.
|
||||
func GetFdInfo(in interface{}) (uintptr, bool) {
|
||||
func getFdInfo(in interface{}) (uintptr, bool) {
|
||||
return windowsconsole.GetHandleInfo(in)
|
||||
}
|
||||
|
||||
// GetWinsize returns the window size based on the specified file descriptor.
|
||||
func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
func getWinsize(fd uintptr) (*Winsize, error) {
|
||||
var info windows.ConsoleScreenBufferInfo
|
||||
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil {
|
||||
return nil, err
|
||||
@@ -110,21 +102,21 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
return winsize, nil
|
||||
}
|
||||
|
||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
func setWinsize(fd uintptr, ws *Winsize) error {
|
||||
return fmt.Errorf("not implemented on Windows")
|
||||
}
|
||||
|
||||
func isTerminal(fd uintptr) bool {
|
||||
var mode uint32
|
||||
err := windows.GetConsoleMode(windows.Handle(fd), &mode)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// RestoreTerminal restores the terminal connected to the given file descriptor
|
||||
// to a previous state.
|
||||
func RestoreTerminal(fd uintptr, state *State) error {
|
||||
func restoreTerminal(fd uintptr, state *State) error {
|
||||
return windows.SetConsoleMode(windows.Handle(fd), state.mode)
|
||||
}
|
||||
|
||||
// SaveState saves the state of the terminal connected to the given file descriptor.
|
||||
func SaveState(fd uintptr) (*State, error) {
|
||||
func saveState(fd uintptr) (*State, error) {
|
||||
var mode uint32
|
||||
|
||||
if err := windows.GetConsoleMode(windows.Handle(fd), &mode); err != nil {
|
||||
@@ -134,9 +126,8 @@ func SaveState(fd uintptr) (*State, error) {
|
||||
return &State{mode: mode}, nil
|
||||
}
|
||||
|
||||
// DisableEcho disables echo for the terminal connected to the given file descriptor.
|
||||
// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
func DisableEcho(fd uintptr, state *State) error {
|
||||
func disableEcho(fd uintptr, state *State) error {
|
||||
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
mode := state.mode
|
||||
mode &^= windows.ENABLE_ECHO_INPUT
|
||||
mode |= windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT
|
||||
@@ -150,69 +141,27 @@ func DisableEcho(fd uintptr, state *State) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetRawTerminal puts the terminal connected to the given file descriptor into
|
||||
// raw mode and returns the previous state. On UNIX, this puts both the input
|
||||
// and output into raw mode. On Windows, it only puts the input into raw mode.
|
||||
func SetRawTerminal(fd uintptr) (*State, error) {
|
||||
state, err := MakeRaw(fd)
|
||||
func setRawTerminal(fd uintptr) (*State, error) {
|
||||
oldState, err := MakeRaw(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Register an interrupt handler to catch and restore prior state
|
||||
restoreAtInterrupt(fd, state)
|
||||
return state, err
|
||||
restoreAtInterrupt(fd, oldState)
|
||||
return oldState, err
|
||||
}
|
||||
|
||||
// SetRawTerminalOutput puts the output of terminal connected to the given file
|
||||
// descriptor into raw mode. On UNIX, this does nothing and returns nil for the
|
||||
// state. On Windows, it disables LF -> CRLF translation.
|
||||
func SetRawTerminalOutput(fd uintptr) (*State, error) {
|
||||
state, err := SaveState(fd)
|
||||
func setRawTerminalOutput(fd uintptr) (*State, error) {
|
||||
oldState, err := saveState(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Ignore failures, since winterm.DISABLE_NEWLINE_AUTO_RETURN might not be supported on this
|
||||
// version of Windows.
|
||||
_ = windows.SetConsoleMode(windows.Handle(fd), state.mode|windows.DISABLE_NEWLINE_AUTO_RETURN)
|
||||
return state, err
|
||||
}
|
||||
|
||||
// MakeRaw puts the terminal (Windows Console) connected to the given file descriptor into raw
|
||||
// mode and returns the previous state of the terminal so that it can be restored.
|
||||
func MakeRaw(fd uintptr) (*State, error) {
|
||||
state, err := SaveState(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode := state.mode
|
||||
|
||||
// See
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
|
||||
// Disable these modes
|
||||
mode &^= windows.ENABLE_ECHO_INPUT
|
||||
mode &^= windows.ENABLE_LINE_INPUT
|
||||
mode &^= windows.ENABLE_MOUSE_INPUT
|
||||
mode &^= windows.ENABLE_WINDOW_INPUT
|
||||
mode &^= windows.ENABLE_PROCESSED_INPUT
|
||||
|
||||
// Enable these modes
|
||||
mode |= windows.ENABLE_EXTENDED_FLAGS
|
||||
mode |= windows.ENABLE_INSERT_MODE
|
||||
mode |= windows.ENABLE_QUICK_EDIT_MODE
|
||||
if vtInputSupported {
|
||||
mode |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||
}
|
||||
|
||||
err = windows.SetConsoleMode(windows.Handle(fd), mode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return state, nil
|
||||
_ = windows.SetConsoleMode(windows.Handle(fd), oldState.mode|windows.DISABLE_NEWLINE_AUTO_RETURN)
|
||||
return oldState, err
|
||||
}
|
||||
|
||||
func restoreAtInterrupt(fd uintptr, state *State) {
|
||||
|
||||
Generated
Vendored
+6
-7
@@ -8,12 +8,11 @@ import (
|
||||
)
|
||||
|
||||
// Termios is the Unix API for terminal I/O.
|
||||
//
|
||||
// Deprecated: use [unix.Termios].
|
||||
type Termios = unix.Termios
|
||||
|
||||
// MakeRaw puts the terminal connected to the given file descriptor into raw
|
||||
// mode and returns the previous state of the terminal so that it can be
|
||||
// restored.
|
||||
func MakeRaw(fd uintptr) (*State, error) {
|
||||
func makeRaw(fd uintptr) (*State, error) {
|
||||
termios, err := tcget(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -21,10 +20,10 @@ func MakeRaw(fd uintptr) (*State, error) {
|
||||
|
||||
oldState := State{termios: *termios}
|
||||
|
||||
termios.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
|
||||
termios.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON
|
||||
termios.Oflag &^= unix.OPOST
|
||||
termios.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
|
||||
termios.Cflag &^= (unix.CSIZE | unix.PARENB)
|
||||
termios.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN
|
||||
termios.Cflag &^= unix.CSIZE | unix.PARENB
|
||||
termios.Cflag |= unix.CS8
|
||||
termios.Cc[unix.VMIN] = 1
|
||||
termios.Cc[unix.VTIME] = 0
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package term
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
func makeRaw(fd uintptr) (*State, error) {
|
||||
state, err := SaveState(fd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode := state.mode
|
||||
|
||||
// See
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
|
||||
// -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
|
||||
|
||||
// Disable these modes
|
||||
mode &^= windows.ENABLE_ECHO_INPUT
|
||||
mode &^= windows.ENABLE_LINE_INPUT
|
||||
mode &^= windows.ENABLE_MOUSE_INPUT
|
||||
mode &^= windows.ENABLE_WINDOW_INPUT
|
||||
mode &^= windows.ENABLE_PROCESSED_INPUT
|
||||
|
||||
// Enable these modes
|
||||
mode |= windows.ENABLE_EXTENDED_FLAGS
|
||||
mode |= windows.ENABLE_INSERT_MODE
|
||||
mode |= windows.ENABLE_QUICK_EDIT_MODE
|
||||
if vtInputSupported {
|
||||
mode |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||
}
|
||||
|
||||
err = windows.SetConsoleMode(windows.Handle(fd), mode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
+2
-2
@@ -195,10 +195,10 @@ func keyToString(keyEvent *winterm.KEY_EVENT_RECORD, escapeSequence []byte) stri
|
||||
|
||||
// <Alt>+Key generates ESC N Key
|
||||
if !control && alt {
|
||||
return ansiterm.KEY_ESC_N + strings.ToLower(string(keyEvent.UnicodeChar))
|
||||
return ansiterm.KEY_ESC_N + strings.ToLower(string(rune(keyEvent.UnicodeChar)))
|
||||
}
|
||||
|
||||
return string(keyEvent.UnicodeChar)
|
||||
return string(rune(keyEvent.UnicodeChar))
|
||||
}
|
||||
|
||||
// formatVirtualKey converts a virtual key (e.g., up arrow) into the appropriate ANSI string.
|
||||
|
||||
+5
-2
@@ -30,8 +30,11 @@ func GetHandleInfo(in interface{}) (uintptr, bool) {
|
||||
|
||||
// IsConsole returns true if the given file descriptor is a Windows Console.
|
||||
// The code assumes that GetConsoleMode will return an error for file descriptors that are not a console.
|
||||
// Deprecated: use golang.org/x/sys/windows.GetConsoleMode() or golang.org/x/term.IsTerminal()
|
||||
var IsConsole = isConsole
|
||||
//
|
||||
// Deprecated: use [windows.GetConsoleMode] or [golang.org/x/term.IsTerminal].
|
||||
func IsConsole(fd uintptr) bool {
|
||||
return isConsole(fd)
|
||||
}
|
||||
|
||||
func isConsole(fd uintptr) bool {
|
||||
var mode uint32
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package term
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// GetWinsize returns the window size based on the specified file descriptor.
|
||||
func GetWinsize(fd uintptr) (*Winsize, error) {
|
||||
uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
|
||||
ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
|
||||
return ws, err
|
||||
}
|
||||
|
||||
// SetWinsize tries to set the specified window size for the specified file descriptor.
|
||||
func SetWinsize(fd uintptr, ws *Winsize) error {
|
||||
uws := &unix.Winsize{Row: ws.Height, Col: ws.Width, Xpixel: ws.x, Ypixel: ws.y}
|
||||
return unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, uws)
|
||||
}
|
||||
Reference in New Issue
Block a user