Compare commits

...
7 Commits
Author SHA1 Message Date
Jakob Borg 612fdff377 build: automatically update APT repository on release
This uses https://github.com/kastelo/ezapt to generate and sign the
archive, and uploads it to blob storage.
2024-11-24 22:55:12 +01:00
Jakob BorgandSimon Frei 8ccb7f1924 fix(protocol): allow encrypted-to-encrypted connections again
Encrypted-to-encrypted connections (i.e., ones where both sides set a
password) used to work but were broken in the 1.28.0 release. The
culprit is the 5342bec1b refactor which slightly changed how the request
was constructed, resulting in a bad block hash field.

Co-authored-by: Simon Frei <freisim93@gmail.com>
2024-11-24 22:55:12 +01:00
André ColombandGitHub 65d0ca8aa9 fix(config): respect GUI address override in fresh default config (fixes #9783) (#9675)
### Purpose

When generating a new `config.xml` file with default options, the GUI
address is populated with a hard-coded default value of
`127.0.0.1:8384`, except for a random free port if that default one is
occupied. This is independent from the GUI configuration default address
defined in the protobuf description. More importantly, it ignores any
`STGUIADDRESS` override given via environment variable or command-line
option, thus probing for the default port instead of the one specified
via override.

The `ProbeFreePorts()` function now respects the override, by reading
the `GUIConfiguration.Address()` method instead of using hard-coded
defaults.

When not calling `ProbeFreePorts()`, the override should still be
persisted rather than the default address. This happens only when
generating a fresh default `config.xml`, never on an existing one.
2024-11-19 11:01:43 +00:00
Jakob BorgandGitHub e82ed6e3d3 style: gofumpt all the things (#9829)
Literally `gofumpt -w .` from the top level dir. Guaranteed to be minor
style changes only and nothing else.

@imsodin per request?
2024-11-19 11:32:56 +01:00
Syncthing Release Automation 4b815fc086 chore(gui, man, authors): update docs, translations, and contributors 2024-11-18 03:49:35 +00:00
Jakob BorgandGitHub 7eaf843de2 chore(api): add block and goroutine profiles to support bundle (#9824) 2024-11-16 09:43:17 +01:00
Jakob BorgandGitHub 110e1ae6f9 fix(model): don't panic in index consistency print (fixes #9821) (#9823)
We try to compare to the last fileinfo, but apparently we can end up
here with an empty file list and crash on out of index.
2024-11-14 19:59:34 +00:00
95 changed files with 541 additions and 420 deletions
+82
View File
@@ -725,6 +725,88 @@ jobs:
with:
args: sync objstore:${{ secrets.S3_BUCKET }}/release/${{ env.VERSION }} objstore:${{ secrets.S3_BUCKET }}/release/latest
#
# Push Debian/APT archive
#
publish-apt:
name: Publish APT
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && (github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/heads/release-'))
environment: signing
needs:
- basics
- package-debian
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download packages
uses: actions/download-artifact@v4
with:
name: debian-packages
path: packages
- name: Set version
run: |
version=$(go run build.go version)
echo "Version: $version"
echo "VERSION=$version" >> $GITHUB_ENV
# Decide whether packages should go to stable, candidate or nightly
- name: Prepare packages
run: |
kind=stable
if [[ $VERSION == *-rc.[0-9] ]] ; then
kind=candidate
elif [[ $VERSION == *-* ]] ; then
kind=nightly
fi
echo "Kind: $kind"
mkdir -p packages/syncthing/$kind
mv packages/*.deb packages/syncthing/$kind
- name: Pull archive
uses: docker://docker.io/rclone/rclone:latest
env:
RCLONE_CONFIG_OBJSTORE_TYPE: s3
RCLONE_CONFIG_OBJSTORE_PROVIDER: ${{ secrets.S3_PROVIDER }}
RCLONE_CONFIG_OBJSTORE_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
RCLONE_CONFIG_OBJSTORE_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
RCLONE_CONFIG_OBJSTORE_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
RCLONE_CONFIG_OBJSTORE_REGION: ${{ secrets.S3_REGION }}
RCLONE_CONFIG_OBJSTORE_ACL: public-read
with:
args: sync objstore:syncthing-apt/dists dists
- name: Prepare signing key
run: |
echo "$APT_GPG_KEYRING_BASE64" | base64 -d > keyring.pgp
env:
APT_GPG_KEYRING_BASE64: ${{ secrets.APT_GPG_KEYRING_BASE64 }}
- name: Update archive
uses: docker://ghcr.io/kastelo/ezapt:latest
with:
args:
--add packages
--dists dists
--keyring keyring.pgp
- name: Push archive
uses: docker://docker.io/rclone/rclone:latest
env:
RCLONE_CONFIG_OBJSTORE_TYPE: s3
RCLONE_CONFIG_OBJSTORE_PROVIDER: ${{ secrets.S3_PROVIDER }}
RCLONE_CONFIG_OBJSTORE_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
RCLONE_CONFIG_OBJSTORE_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
RCLONE_CONFIG_OBJSTORE_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
RCLONE_CONFIG_OBJSTORE_REGION: ${{ secrets.S3_REGION }}
RCLONE_CONFIG_OBJSTORE_ACL: public-read
with:
args: sync dists -v objstore:syncthing-apt/dists
#
# Build and push to Docker Hub
#
+2
View File
@@ -146,6 +146,7 @@ Han Boetes <han@boetes.org>
HansK-p <42314815+HansK-p@users.noreply.github.com>
Harrison Jones (harrisonhjones) <harrisonhjones@users.noreply.github.com>
Heiko Zuerker (Smiley73) <heiko@zuerker.org>
Hireworks <129852174+hireworksltd@users.noreply.github.com>
Hugo Locurcio <hugo.locurcio@hugo.pro>
Iain Barnett <iainspeed@gmail.com>
Ian Johnson (anonymouse64) <ian.johnson@canonical.com> <person.uwsome@gmail.com>
@@ -325,6 +326,7 @@ Thomas Hipp <thomashipp@gmail.com>
Tim Abell (timabell) <tim@timwise.co.uk>
Tim Howes (timhowes) <timhowes@berkeley.edu>
Tim Nordenfur <tim@gurka.se>
Tobias Frölich <40638719+tobifroe@users.noreply.github.com>
Tobias Klauser <tobias.klauser@gmail.com>
Tobias Nygren (tnn2) <tnn@nygren.pp.se>
Tobias Tom (tobiastom) <t.tom@succont.de>
+72 -72
View File
@@ -97,40 +97,40 @@ var targets = map[string]target{
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/syncthing"},
binaryName: "syncthing", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
{src: "README.md", dst: "README.txt", perm: 0644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
{src: "{{binary}}", dst: "{{binary}}", perm: 0o755},
{src: "README.md", dst: "README.txt", perm: 0o644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0o644},
// All files from etc/ and extra/ added automatically in init().
},
systemdService: "syncthing@*.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing/LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing/AUTHORS.txt", perm: 0644},
{src: "man/syncthing.1", dst: "deb/usr/share/man/man1/syncthing.1", perm: 0644},
{src: "man/syncthing-config.5", dst: "deb/usr/share/man/man5/syncthing-config.5", perm: 0644},
{src: "man/syncthing-stignore.5", dst: "deb/usr/share/man/man5/syncthing-stignore.5", perm: 0644},
{src: "man/syncthing-device-ids.7", dst: "deb/usr/share/man/man7/syncthing-device-ids.7", perm: 0644},
{src: "man/syncthing-event-api.7", dst: "deb/usr/share/man/man7/syncthing-event-api.7", perm: 0644},
{src: "man/syncthing-faq.7", dst: "deb/usr/share/man/man7/syncthing-faq.7", perm: 0644},
{src: "man/syncthing-networking.7", dst: "deb/usr/share/man/man7/syncthing-networking.7", perm: 0644},
{src: "man/syncthing-rest-api.7", dst: "deb/usr/share/man/man7/syncthing-rest-api.7", perm: 0644},
{src: "man/syncthing-security.7", dst: "deb/usr/share/man/man7/syncthing-security.7", perm: 0644},
{src: "man/syncthing-versioning.7", dst: "deb/usr/share/man/man7/syncthing-versioning.7", perm: 0644},
{src: "etc/linux-systemd/system/syncthing@.service", dst: "deb/lib/systemd/system/syncthing@.service", perm: 0644},
{src: "etc/linux-systemd/user/syncthing.service", dst: "deb/usr/lib/systemd/user/syncthing.service", perm: 0644},
{src: "etc/linux-sysctl/30-syncthing.conf", dst: "deb/usr/lib/sysctl.d/30-syncthing.conf", perm: 0644},
{src: "etc/firewall-ufw/syncthing", dst: "deb/etc/ufw/applications.d/syncthing", perm: 0644},
{src: "etc/linux-desktop/syncthing-start.desktop", dst: "deb/usr/share/applications/syncthing-start.desktop", perm: 0644},
{src: "etc/linux-desktop/syncthing-ui.desktop", dst: "deb/usr/share/applications/syncthing-ui.desktop", perm: 0644},
{src: "assets/logo-32.png", dst: "deb/usr/share/icons/hicolor/32x32/apps/syncthing.png", perm: 0644},
{src: "assets/logo-64.png", dst: "deb/usr/share/icons/hicolor/64x64/apps/syncthing.png", perm: 0644},
{src: "assets/logo-128.png", dst: "deb/usr/share/icons/hicolor/128x128/apps/syncthing.png", perm: 0644},
{src: "assets/logo-256.png", dst: "deb/usr/share/icons/hicolor/256x256/apps/syncthing.png", perm: 0644},
{src: "assets/logo-512.png", dst: "deb/usr/share/icons/hicolor/512x512/apps/syncthing.png", perm: 0644},
{src: "assets/logo-only.svg", dst: "deb/usr/share/icons/hicolor/scalable/apps/syncthing.svg", perm: 0644},
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0o755},
{src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0o644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing/LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing/AUTHORS.txt", perm: 0o644},
{src: "man/syncthing.1", dst: "deb/usr/share/man/man1/syncthing.1", perm: 0o644},
{src: "man/syncthing-config.5", dst: "deb/usr/share/man/man5/syncthing-config.5", perm: 0o644},
{src: "man/syncthing-stignore.5", dst: "deb/usr/share/man/man5/syncthing-stignore.5", perm: 0o644},
{src: "man/syncthing-device-ids.7", dst: "deb/usr/share/man/man7/syncthing-device-ids.7", perm: 0o644},
{src: "man/syncthing-event-api.7", dst: "deb/usr/share/man/man7/syncthing-event-api.7", perm: 0o644},
{src: "man/syncthing-faq.7", dst: "deb/usr/share/man/man7/syncthing-faq.7", perm: 0o644},
{src: "man/syncthing-networking.7", dst: "deb/usr/share/man/man7/syncthing-networking.7", perm: 0o644},
{src: "man/syncthing-rest-api.7", dst: "deb/usr/share/man/man7/syncthing-rest-api.7", perm: 0o644},
{src: "man/syncthing-security.7", dst: "deb/usr/share/man/man7/syncthing-security.7", perm: 0o644},
{src: "man/syncthing-versioning.7", dst: "deb/usr/share/man/man7/syncthing-versioning.7", perm: 0o644},
{src: "etc/linux-systemd/system/syncthing@.service", dst: "deb/lib/systemd/system/syncthing@.service", perm: 0o644},
{src: "etc/linux-systemd/user/syncthing.service", dst: "deb/usr/lib/systemd/user/syncthing.service", perm: 0o644},
{src: "etc/linux-sysctl/30-syncthing.conf", dst: "deb/usr/lib/sysctl.d/30-syncthing.conf", perm: 0o644},
{src: "etc/firewall-ufw/syncthing", dst: "deb/etc/ufw/applications.d/syncthing", perm: 0o644},
{src: "etc/linux-desktop/syncthing-start.desktop", dst: "deb/usr/share/applications/syncthing-start.desktop", perm: 0o644},
{src: "etc/linux-desktop/syncthing-ui.desktop", dst: "deb/usr/share/applications/syncthing-ui.desktop", perm: 0o644},
{src: "assets/logo-32.png", dst: "deb/usr/share/icons/hicolor/32x32/apps/syncthing.png", perm: 0o644},
{src: "assets/logo-64.png", dst: "deb/usr/share/icons/hicolor/64x64/apps/syncthing.png", perm: 0o644},
{src: "assets/logo-128.png", dst: "deb/usr/share/icons/hicolor/128x128/apps/syncthing.png", perm: 0o644},
{src: "assets/logo-256.png", dst: "deb/usr/share/icons/hicolor/256x256/apps/syncthing.png", perm: 0o644},
{src: "assets/logo-512.png", dst: "deb/usr/share/icons/hicolor/512x512/apps/syncthing.png", perm: 0o644},
{src: "assets/logo-only.svg", dst: "deb/usr/share/icons/hicolor/scalable/apps/syncthing.svg", perm: 0o644},
},
},
"stdiscosrv": {
@@ -142,21 +142,21 @@ var targets = map[string]target{
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stdiscosrv"},
binaryName: "stdiscosrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
{src: "cmd/stdiscosrv/README.md", dst: "README.txt", perm: 0644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
{src: "{{binary}}", dst: "{{binary}}", perm: 0o755},
{src: "cmd/stdiscosrv/README.md", dst: "README.txt", perm: 0o644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0o644},
},
systemdService: "stdiscosrv.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "cmd/stdiscosrv/README.md", dst: "deb/usr/share/doc/syncthing-discosrv/README.txt", perm: 0644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-discosrv/LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-discosrv/AUTHORS.txt", perm: 0644},
{src: "man/stdiscosrv.1", dst: "deb/usr/share/man/man1/stdiscosrv.1", perm: 0644},
{src: "cmd/stdiscosrv/etc/linux-systemd/stdiscosrv.service", dst: "deb/lib/systemd/system/stdiscosrv.service", perm: 0644},
{src: "cmd/stdiscosrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-discosrv", perm: 0644},
{src: "cmd/stdiscosrv/etc/firewall-ufw/stdiscosrv", dst: "deb/etc/ufw/applications.d/stdiscosrv", perm: 0644},
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0o755},
{src: "cmd/stdiscosrv/README.md", dst: "deb/usr/share/doc/syncthing-discosrv/README.txt", perm: 0o644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-discosrv/LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-discosrv/AUTHORS.txt", perm: 0o644},
{src: "man/stdiscosrv.1", dst: "deb/usr/share/man/man1/stdiscosrv.1", perm: 0o644},
{src: "cmd/stdiscosrv/etc/linux-systemd/stdiscosrv.service", dst: "deb/lib/systemd/system/stdiscosrv.service", perm: 0o644},
{src: "cmd/stdiscosrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-discosrv", perm: 0o644},
{src: "cmd/stdiscosrv/etc/firewall-ufw/stdiscosrv", dst: "deb/etc/ufw/applications.d/stdiscosrv", perm: 0o644},
},
tags: []string{"purego"},
},
@@ -169,23 +169,23 @@ var targets = map[string]target{
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/strelaysrv"},
binaryName: "strelaysrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
{src: "cmd/strelaysrv/README.md", dst: "README.txt", perm: 0644},
{src: "cmd/strelaysrv/LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
{src: "{{binary}}", dst: "{{binary}}", perm: 0o755},
{src: "cmd/strelaysrv/README.md", dst: "README.txt", perm: 0o644},
{src: "cmd/strelaysrv/LICENSE", dst: "LICENSE.txt", perm: 0o644},
{src: "LICENSE", dst: "LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0o644},
},
systemdService: "strelaysrv.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "cmd/strelaysrv/README.md", dst: "deb/usr/share/doc/syncthing-relaysrv/README.txt", perm: 0644},
{src: "cmd/strelaysrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaysrv/AUTHORS.txt", perm: 0644},
{src: "man/strelaysrv.1", dst: "deb/usr/share/man/man1/strelaysrv.1", perm: 0644},
{src: "cmd/strelaysrv/etc/linux-systemd/strelaysrv.service", dst: "deb/lib/systemd/system/strelaysrv.service", perm: 0644},
{src: "cmd/strelaysrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-relaysrv", perm: 0644},
{src: "cmd/strelaysrv/etc/firewall-ufw/strelaysrv", dst: "deb/etc/ufw/applications.d/strelaysrv", perm: 0644},
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0o755},
{src: "cmd/strelaysrv/README.md", dst: "deb/usr/share/doc/syncthing-relaysrv/README.txt", perm: 0o644},
{src: "cmd/strelaysrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0o644},
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaysrv/AUTHORS.txt", perm: 0o644},
{src: "man/strelaysrv.1", dst: "deb/usr/share/man/man1/strelaysrv.1", perm: 0o644},
{src: "cmd/strelaysrv/etc/linux-systemd/strelaysrv.service", dst: "deb/lib/systemd/system/strelaysrv.service", perm: 0o644},
{src: "cmd/strelaysrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-relaysrv", perm: 0o644},
{src: "cmd/strelaysrv/etc/firewall-ufw/strelaysrv", dst: "deb/etc/ufw/applications.d/strelaysrv", perm: 0o644},
},
},
"strelaypoolsrv": {
@@ -196,16 +196,16 @@ var targets = map[string]target{
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/infra/strelaypoolsrv"},
binaryName: "strelaypoolsrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
{src: "cmd/infra/strelaypoolsrv/README.md", dst: "README.txt", perm: 0644},
{src: "cmd/infra/strelaypoolsrv/LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
{src: "{{binary}}", dst: "{{binary}}", perm: 0o755},
{src: "cmd/infra/strelaypoolsrv/README.md", dst: "README.txt", perm: 0o644},
{src: "cmd/infra/strelaypoolsrv/LICENSE", dst: "LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0o644},
},
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "cmd/infra/strelaypoolsrv/README.md", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/README.txt", perm: 0644},
{src: "cmd/infra/strelaypoolsrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/AUTHORS.txt", perm: 0644},
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0o755},
{src: "cmd/infra/strelaypoolsrv/README.md", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/README.txt", perm: 0o644},
{src: "cmd/infra/strelaypoolsrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/LICENSE.txt", perm: 0o644},
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/AUTHORS.txt", perm: 0o644},
},
},
"stupgrades": {
@@ -244,13 +244,13 @@ func initTargets() {
// and "extra" dirs.
syncthingPkg := targets["syncthing"]
for _, file := range listFiles("etc") {
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0644})
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0o644})
}
for _, file := range listFiles("extra") {
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0644})
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0o644})
}
for _, file := range listFiles("extra") {
syncthingPkg.installationFiles = append(syncthingPkg.installationFiles, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0644})
syncthingPkg.installationFiles = append(syncthingPkg.installationFiles, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0o644})
}
targets["syncthing"] = syncthingPkg
}
@@ -750,7 +750,7 @@ func shouldBuildSyso(dir string) (string, error) {
}
jsonPath := filepath.Join(dir, "versioninfo.json")
err = os.WriteFile(jsonPath, bs, 0644)
err = os.WriteFile(jsonPath, bs, 0o644)
if err != nil {
return "", errors.New("failed to create " + jsonPath + ": " + err.Error())
}
@@ -809,7 +809,7 @@ func copyFile(src, dst string, perm os.FileMode) error {
}
copy:
os.MkdirAll(filepath.Dir(dst), 0777)
os.MkdirAll(filepath.Dir(dst), 0o777)
if err := os.WriteFile(dst, in, perm); err != nil {
return err
}
@@ -869,7 +869,7 @@ func buildNextGenGUI() bool {
for _, src := range listFiles("next-gen-gui/dist") {
rel, _ := filepath.Rel("next-gen-gui/dist", src)
dst := filepath.Join("gui", rel)
if err := copyFile(src, dst, 0644); err != nil {
if err := copyFile(src, dst, 0o644); err != nil {
fmt.Println("copy:", err)
os.Exit(1)
}
@@ -930,7 +930,7 @@ func proto() {
path := filepath.Join("repos", "protobuf")
runPrint(goCmd, "install", fmt.Sprintf("github.com/gogo/protobuf/protoc-gen-gogofast@%v", pv))
os.MkdirAll("repos", 0755)
os.MkdirAll("repos", 0o755)
if _, err := os.Stat(path); err != nil {
runPrint("git", "clone", repo, path)
@@ -1427,7 +1427,7 @@ func windowsCodesign(file string) {
log.Println("Codesign: signing failed: creating temp file:", err)
return
}
_ = f.Chmod(0600) // best effort remove other users' access
_ = f.Chmod(0o600) // best effort remove other users' access
defer os.Remove(f.Name())
if _, err := f.Write(bs); err != nil {
log.Println("Codesign: signing failed: writing temp file:", err)
@@ -71,7 +71,6 @@ func (l *githubSourceCodeLoader) Load(filename string, line, context int) ([][]b
url := urlPrefix + l.version + filename[idx:]
resp, err := l.client.Get(url)
if err != nil {
fmt.Println("Loading source:", err)
return nil, 0
+1 -1
View File
@@ -52,5 +52,5 @@ func compressAndWrite(bs []byte, fullPath string) error {
gw.Close()
// Create an output file with the compressed report
return os.WriteFile(fullPath, buf.Bytes(), 0644)
return os.WriteFile(fullPath, buf.Bytes(), 0o644)
}
-1
View File
@@ -68,7 +68,6 @@ func findSession(key string) *session {
ses, ok := pendingSessions[key]
if !ok {
return nil
}
delete(pendingSessions, key)
return ses
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("main", "Main package")
)
var l = logger.DefaultLogger.NewFacility("main", "Main package")
+1 -1
View File
@@ -140,7 +140,7 @@ func checkNotExist(t *testing.T, name string) {
func TestAutoClosedFile(t *testing.T) {
os.RemoveAll("_autoclose")
defer os.RemoveAll("_autoclose")
os.Mkdir("_autoclose", 0755)
os.Mkdir("_autoclose", 0o755)
file := filepath.FromSlash("_autoclose/tmp")
data := []byte("hello, world\n")
@@ -30,7 +30,7 @@
<h4 class="text-center" translate>The Syncthing Authors</h4>
<div class="row">
<div class="col-md-12" id="contributor-list">
Jakob Borg, Audrius Butkevicius, Jesse Lucas, Simon Frei, Tomasz Wilczyński, Alexander Graf, Alexandre Viau, Anderson Mesquita, André Colomb, Antony Male, Ben Schulz, Caleb Callaway, Daniel Harte, Emil Lundberg, Eric P, Evgeny Kuznetsov, Lars K.W. Gohlke, Lode Hoste, Michael Ploujnikov, Nate Morrison, Philippe Schommers, Ryan Sullivan, Sergey Mishin, Stefan Tatschner, Wulf Weich, bt90, greatroar, Aaron Bieber, Adam Piggott, Adel Qalieh, Alan Pope, Alberto Donato, Aleksey Vasenev, Alessandro G., Alex Lindeman, Alex Xu, Alexander Seiler, Alexandre Alves, Aman Gupta, Anatoli Babenia, Andreas Sommer, Andrew Dunham, Andrew Meyer, Andrew Rabert, Andrey D, Anjan Momi, Anthony Goeckner, Antoine Lamielle, Anur, Aranjedeath, Arkadiusz Tymiński, Aroun, Arthur Axel fREW Schmidt, Artur Zubilewicz, Aurélien Rainone, BAHADIR YILMAZ, Bart De Vries, Beat Reichenbach, Ben Curthoys, Ben Shepherd, Ben Sidhom, Benedikt Heine, Benedikt Morbach, Benjamin Nater, Benno Fünfstück, Benny Ng, Boqin Qin, Boris Rybalkin, Brandon Philips, Brendan Long, Brian R. Becker, Carsten Hagemann, Catfriend1, Cathryne Linenweaver, Cedric Staniewski, Chih-Hsuan Yen, Choongkyu, Chris Howie, Chris Joel, Chris Tonkinson, Christian Kujau, Christian Prescott, Colin Kennedy, Cromefire_, Cyprien Devillez, Dale Visser, Dan, Daniel Barczyk, Daniel Bergmann, Daniel Martí, Daniel Padrta, Darshil Chanpura, David Rimmer, DeflateAwning, Denis A., Dennis Wilson, DerRockWolf, Devon G. Redekopp, Dimitri Papadopoulos Orfanos, Dmitry Saveliev, Domenic Horner, Dominik Heidler, Elias Jarlebring, Elliot Huffman, Emil Hessman, Eng Zer Jun, Eric Lesiuta, Erik Meitner, Evan Spensley, Federico Castagnini, Felix, Felix Ableitner, Felix Lampe, Felix Unterpaintner, Francois-Xavier Gsell, Frank Isemann, Gahl Saraf, Gilli Sigurdsson, Gleb Sinyavskiy, Graham Miln, Greg, Gusted, Han Boetes, HansK-p, Harrison Jones, Heiko Zuerker, Hugo Locurcio, Iain Barnett, Ian Johnson, Ikko Ashimine, Ilya Brin, Iskander Sharipov, Jaakko Hannikainen, Jacek Szafarkiewicz, Jack Croft, Jacob, Jake Peterson, James O'Beirne, James Patterson, Jaroslav Lichtblau, Jaroslav Malec, Jaspitta, Jauder Ho, Jaya Chithra, Jaya Kumar, Jeffery To, Jens Diemer, Jerry Jacobs, Jochen Voss, Johan Andersson, Johan Vromans, John Rinehart, Jonas Thelemann, Jonathan, Jonathan Cross, Jonta, Jose Manuel Delicado, Julian Lehrhuber, Jörg Thalheim, Jędrzej Kula, K.B.Dharun Krishna, Kalle Laine, Kapil Sareen, Karol Różycki, Kebin Liu, Keith Harrison, Keith Turner, Kelong Cong, Ken'ichi Kamada, Kevin Allen, Kevin Bushiri, Kevin White, Jr., Kurt Fitzner, LSmithx2, Lars Lehtonen, Laurent Arnoud, Laurent Etiemble, Leo Arias, Liu Siyuan, Lord Landon Agahnim, Lukas Lihotzki, Luke Hamburg, Majed Abdulaziz, Marc Laporte, Marc Pujol, Marcin Dziadus, Marcus Legendre, Mario Majila, Mark Pulford, Martchus, Martin Polehla, Mateusz Naściszewski, Mateusz Ż, Matic Potočnik, Matt Burke, Matt Robenolt, Matteo Ruina, Maurizio Tomasi, Max, Max Schulze, MaximAL, Maxime Thirouin, Maximilian, MichaIng, Michael Jephcote, Michael Rienstra, Michael Tilli, Migelo, Mike Boone, MikeLund, MikolajTwarog, Mingxuan Lin, Naveen, Nicholas Rishel, Nick Busey, Nico Stapelbroek, Nicolas Braud-Santoni, Nicolas Perraut, Niels Peter Roest, Nils Jakobi, NinoM4ster, Nitroretro, NoLooseEnds, Oliver Freyermuth, Otiel, Oyebanji Jacob Mayowa, Pablo, Pascal Jungblut, Paul Brit, Pawel Palenica, Paweł Rozlach, Peter Badida, Peter Dave Hello, Peter Hoeg, Peter Marquardt, Phani Rithvij, Phil Davis, Phill Luby, Pier Paolo Ramon, Piotr Bejda, Pramodh KP, Quentin Hibon, Rahmi Pruitt, Richard Hartmann, Robert Carosi, Roberto Santalla, Robin Schoonover, Roman Zaynetdinov, Ross Smith II, Ruslan Yevdokymov, Ryan Qian, Sacheendra Talluri, Scott Klupfel, Sertonix, Severin von Wnuck-Lipinski, Shaarad Dalvi, Simon Mwepu, Simon Pickup, Sly_tom_cat, Sonu Kumar Saw, Stefan Kuntz, Steven Eckhoff, Suhas Gundimeda, Sven Bachmann, Taylor Khan, Terrance, Thomas, Thomas Hipp, Tim Abell, Tim Howes, Tim Nordenfur, Tobias Klauser, Tobias Nygren, Tobias Tom, Tom Jakubowski, Tommy Thorn, Tommy van der Vorst, Tully Robinson, Tyler Brazier, Tyler Kropp, Unrud, Veeti Paananen, Victor Buinsky, Vik, Vil Brekin, Vladimir Rusinov, WangXi, Will Rouesnel, William A. Kennington III, Xavier O., Yannic A., andresvia, andyleap, boomsquared, chenrui, chucic, cjc7373, cui fliter, d-volution, derekriemer, desbma, diemade, digital, entity0xfe, georgespatton, ghjklw, guangwu, gudvinr, ignacy123, janost, jaseg, jelle van der Waa, jtagcat, klemens, kylosus, luchenhan, luzpaz, marco-m, maxice8, mclang, mv1005, nf, orangekame3, otbutz, overkill, perewa, red_led, rubenbe, sec65, vapatel2, villekalliomaki, wangguoliang, wouter bolsterlee, xarx00, xjtdy888, 佛跳墙, 落心
Jakob Borg, Audrius Butkevicius, Jesse Lucas, Simon Frei, Tomasz Wilczyński, Alexander Graf, Alexandre Viau, Anderson Mesquita, André Colomb, Antony Male, Ben Schulz, Caleb Callaway, Daniel Harte, Emil Lundberg, Eric P, Evgeny Kuznetsov, Lars K.W. Gohlke, Lode Hoste, Michael Ploujnikov, Nate Morrison, Philippe Schommers, Ryan Sullivan, Sergey Mishin, Stefan Tatschner, Wulf Weich, bt90, greatroar, Aaron Bieber, Adam Piggott, Adel Qalieh, Alan Pope, Alberto Donato, Aleksey Vasenev, Alessandro G., Alex Lindeman, Alex Xu, Alexander Seiler, Alexandre Alves, Aman Gupta, Anatoli Babenia, Andreas Sommer, Andrew Dunham, Andrew Meyer, Andrew Rabert, Andrey D, Anjan Momi, Anthony Goeckner, Antoine Lamielle, Anur, Aranjedeath, Arkadiusz Tymiński, Aroun, Arthur Axel fREW Schmidt, Artur Zubilewicz, Aurélien Rainone, BAHADIR YILMAZ, Bart De Vries, Beat Reichenbach, Ben Curthoys, Ben Shepherd, Ben Sidhom, Benedikt Heine, Benedikt Morbach, Benjamin Nater, Benno Fünfstück, Benny Ng, Boqin Qin, Boris Rybalkin, Brandon Philips, Brendan Long, Brian R. Becker, Carsten Hagemann, Catfriend1, Cathryne Linenweaver, Cedric Staniewski, Chih-Hsuan Yen, Choongkyu, Chris Howie, Chris Joel, Chris Tonkinson, Christian Kujau, Christian Prescott, Colin Kennedy, Cromefire_, Cyprien Devillez, Dale Visser, Dan, Daniel Barczyk, Daniel Bergmann, Daniel Martí, Daniel Padrta, Darshil Chanpura, David Rimmer, DeflateAwning, Denis A., Dennis Wilson, DerRockWolf, Devon G. Redekopp, Dimitri Papadopoulos Orfanos, Dmitry Saveliev, Domenic Horner, Dominik Heidler, Elias Jarlebring, Elliot Huffman, Emil Hessman, Eng Zer Jun, Eric Lesiuta, Erik Meitner, Evan Spensley, Federico Castagnini, Felix, Felix Ableitner, Felix Lampe, Felix Unterpaintner, Francois-Xavier Gsell, Frank Isemann, Gahl Saraf, Gilli Sigurdsson, Gleb Sinyavskiy, Graham Miln, Greg, Gusted, Han Boetes, HansK-p, Harrison Jones, Heiko Zuerker, Hireworks, Hugo Locurcio, Iain Barnett, Ian Johnson, Ikko Ashimine, Ilya Brin, Iskander Sharipov, Jaakko Hannikainen, Jacek Szafarkiewicz, Jack Croft, Jacob, Jake Peterson, James O'Beirne, James Patterson, Jaroslav Lichtblau, Jaroslav Malec, Jaspitta, Jauder Ho, Jaya Chithra, Jaya Kumar, Jeffery To, Jens Diemer, Jerry Jacobs, Jochen Voss, Johan Andersson, Johan Vromans, John Rinehart, Jonas Thelemann, Jonathan, Jonathan Cross, Jonta, Jose Manuel Delicado, Julian Lehrhuber, Jörg Thalheim, Jędrzej Kula, K.B.Dharun Krishna, Kalle Laine, Kapil Sareen, Karol Różycki, Kebin Liu, Keith Harrison, Keith Turner, Kelong Cong, Ken'ichi Kamada, Kevin Allen, Kevin Bushiri, Kevin White, Jr., Kurt Fitzner, LSmithx2, Lars Lehtonen, Laurent Arnoud, Laurent Etiemble, Leo Arias, Liu Siyuan, Lord Landon Agahnim, Lukas Lihotzki, Luke Hamburg, Majed Abdulaziz, Marc Laporte, Marc Pujol, Marcin Dziadus, Marcus Legendre, Mario Majila, Mark Pulford, Martchus, Martin Polehla, Mateusz Naściszewski, Mateusz Ż, Matic Potočnik, Matt Burke, Matt Robenolt, Matteo Ruina, Maurizio Tomasi, Max, Max Schulze, MaximAL, Maxime Thirouin, Maximilian, MichaIng, Michael Jephcote, Michael Rienstra, Michael Tilli, Migelo, Mike Boone, MikeLund, MikolajTwarog, Mingxuan Lin, Naveen, Nicholas Rishel, Nick Busey, Nico Stapelbroek, Nicolas Braud-Santoni, Nicolas Perraut, Niels Peter Roest, Nils Jakobi, NinoM4ster, Nitroretro, NoLooseEnds, Oliver Freyermuth, Otiel, Oyebanji Jacob Mayowa, Pablo, Pascal Jungblut, Paul Brit, Pawel Palenica, Paweł Rozlach, Peter Badida, Peter Dave Hello, Peter Hoeg, Peter Marquardt, Phani Rithvij, Phil Davis, Phill Luby, Pier Paolo Ramon, Piotr Bejda, Pramodh KP, Quentin Hibon, Rahmi Pruitt, Richard Hartmann, Robert Carosi, Roberto Santalla, Robin Schoonover, Roman Zaynetdinov, Ross Smith II, Ruslan Yevdokymov, Ryan Qian, Sacheendra Talluri, Scott Klupfel, Sertonix, Severin von Wnuck-Lipinski, Shaarad Dalvi, Simon Mwepu, Simon Pickup, Sly_tom_cat, Sonu Kumar Saw, Stefan Kuntz, Steven Eckhoff, Suhas Gundimeda, Sven Bachmann, Taylor Khan, Terrance, Thomas, Thomas Hipp, Tim Abell, Tim Howes, Tim Nordenfur, Tobias Frölich, Tobias Klauser, Tobias Nygren, Tobias Tom, Tom Jakubowski, Tommy Thorn, Tommy van der Vorst, Tully Robinson, Tyler Brazier, Tyler Kropp, Unrud, Veeti Paananen, Victor Buinsky, Vik, Vil Brekin, Vladimir Rusinov, WangXi, Will Rouesnel, William A. Kennington III, Xavier O., Yannic A., andresvia, andyleap, boomsquared, chenrui, chucic, cjc7373, cui fliter, d-volution, derekriemer, desbma, diemade, digital, entity0xfe, georgespatton, ghjklw, guangwu, gudvinr, ignacy123, janost, jaseg, jelle van der Waa, jtagcat, klemens, kylosus, luchenhan, luzpaz, marco-m, maxice8, mclang, mv1005, nf, orangekame3, otbutz, overkill, perewa, red_led, rubenbe, sec65, vapatel2, villekalliomaki, wangguoliang, wouter bolsterlee, xarx00, xjtdy888, 佛跳墙, 落心
</div>
</div>
</div>
+39 -16
View File
@@ -1165,6 +1165,7 @@ type fileEntry struct {
func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) {
var files []fileEntry
const profilingDuration = 4 * time.Second
// Redacted configuration as a JSON
if jsonConfig, err := json.MarshalIndent(getRedactedConfig(s), "", " "); err != nil {
@@ -1231,10 +1232,10 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) {
}
// Metrics data as text
buf := bytes.NewBuffer(nil)
wr := bufferedResponseWriter{Writer: buf}
var metricsBuf bytes.Buffer
wr := bufferedResponseWriter{Writer: &metricsBuf}
promhttp.Handler().ServeHTTP(wr, &http.Request{Method: http.MethodGet})
files = append(files, fileEntry{name: "metrics.txt", data: buf.Bytes()})
files = append(files, fileEntry{name: "metrics.txt", data: metricsBuf.Bytes()})
// Connection data as JSON
connStats := s.model.ConnectionStats()
@@ -1244,20 +1245,42 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) {
files = append(files, fileEntry{name: "connection-stats.json.txt", data: connStatsJSON})
}
// Heap and CPU Proofs as a pprof extension
var heapBuffer, cpuBuffer bytes.Buffer
filename := fmt.Sprintf("syncthing-heap-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
runtime.GC()
if err := pprof.WriteHeapProfile(&heapBuffer); err == nil {
files = append(files, fileEntry{name: filename, data: heapBuffer.Bytes()})
// Write a goroutine profile
if p := pprof.Lookup("goroutine"); p != nil {
var goroutineBuf bytes.Buffer
_ = p.WriteTo(&goroutineBuf, 0)
filename := fmt.Sprintf("syncthing-goroutines-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
files = append(files, fileEntry{name: filename, data: goroutineBuf.Bytes()})
}
const duration = 4 * time.Second
filename = fmt.Sprintf("syncthing-cpu-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
if err := pprof.StartCPUProfile(&cpuBuffer); err == nil {
time.Sleep(duration)
// Take a heap profile
var heapBuf bytes.Buffer
runtime.GC()
if err := pprof.WriteHeapProfile(&heapBuf); err == nil {
filename := fmt.Sprintf("syncthing-heap-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
files = append(files, fileEntry{name: filename, data: heapBuf.Bytes()})
}
// Enable block profiling
runtime.SetBlockProfileRate(1)
defer runtime.SetBlockProfileRate(0)
// Take a CPU profile, waiting for the profiling duration. This also
// gives time for the block profile.
var cpuBuf bytes.Buffer
if err := pprof.StartCPUProfile(&cpuBuf); err == nil {
time.Sleep(profilingDuration)
pprof.StopCPUProfile()
files = append(files, fileEntry{name: filename, data: cpuBuffer.Bytes()})
filename := fmt.Sprintf("syncthing-cpu-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
files = append(files, fileEntry{name: filename, data: cpuBuf.Bytes()})
}
// Write the block profile
if p := pprof.Lookup("block"); p != nil {
var blockBuf bytes.Buffer
_ = p.WriteTo(&blockBuf, 0)
filename := fmt.Sprintf("syncthing-block-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, build.Version, time.Now().Format("150405")) // hhmmss
files = append(files, fileEntry{name: filename, data: blockBuf.Bytes()})
}
// Add buffer files to buffer zip
@@ -1483,7 +1506,7 @@ func (*service) getDeviceID(w http.ResponseWriter, r *http.Request) {
func (*service) getLang(w http.ResponseWriter, r *http.Request) {
lang := r.Header.Get("Accept-Language")
var weights = make(map[string]float64)
weights := make(map[string]float64)
for _, l := range strings.Split(lang, ",") {
parts := strings.SplitN(l, ";", 2)
code := strings.ToLower(strings.TrimSpace(parts[0]))
@@ -1502,7 +1525,7 @@ func (*service) getLang(w http.ResponseWriter, r *http.Request) {
weights[code] = q
}
}
var langs = make([]string, 0, len(weights))
langs := make([]string, 0, len(weights))
for code := range weights {
langs = append(langs, code)
}
+1 -1
View File
@@ -148,7 +148,7 @@ func readBroadcasts(ctx context.Context, outbox chan<- recv, port int) error {
}
func bcast(ip *net.IPNet) *net.IPNet {
var bc = &net.IPNet{}
bc := &net.IPNet{}
bc.IP = make([]byte, len(ip.IP))
copy(bc.IP, ip.IP)
bc.Mask = ip.Mask
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("beacon", "Multicast and broadcast discovery")
)
var l = logger.DefaultLogger.NewFacility("beacon", "Multicast and broadcast discovery")
+4
View File
@@ -18,6 +18,7 @@ type requiresRestart struct {
func (requiresRestart) VerifyConfiguration(_, _ Configuration) error {
return nil
}
func (c requiresRestart) CommitConfiguration(_, _ Configuration) bool {
select {
case c.committed <- struct{}{}:
@@ -25,6 +26,7 @@ func (c requiresRestart) CommitConfiguration(_, _ Configuration) bool {
}
return false
}
func (requiresRestart) String() string {
return "requiresRestart"
}
@@ -34,9 +36,11 @@ type validationError struct{}
func (validationError) VerifyConfiguration(_, _ Configuration) error {
return errors.New("some error")
}
func (validationError) CommitConfiguration(_, _ Configuration) bool {
return true
}
func (validationError) String() string {
return "validationError"
}
+10 -3
View File
@@ -49,7 +49,6 @@ var (
"dynamic+https://relays.syncthing.net/endpoint",
netutil.AddressURL("quic", net.JoinHostPort("0.0.0.0", strconv.Itoa(DefaultQUICPort))),
}
DefaultGUIPort = 8384
// DefaultDiscoveryServersV4 should be substituted when the configuration
// contains <globalAnnounceServer>default-v4</globalAnnounceServer>.
DefaultDiscoveryServersV4 = []string{
@@ -116,11 +115,19 @@ func New(myID protocol.DeviceID) Configuration {
}
func (cfg *Configuration) ProbeFreePorts() error {
port, err := getFreePort("127.0.0.1", DefaultGUIPort)
guiHost, guiPort, err := net.SplitHostPort(cfg.GUI.Address())
if err != nil {
return fmt.Errorf("get default port (GUI): %w", err)
}
port, err := strconv.Atoi(guiPort)
if err != nil {
return fmt.Errorf("convert default port (GUI): %w", err)
}
port, err = getFreePort(guiHost, port)
if err != nil {
return fmt.Errorf("get free port (GUI): %w", err)
}
cfg.GUI.RawAddress = fmt.Sprintf("127.0.0.1:%d", port)
cfg.GUI.RawAddress = net.JoinHostPort(guiHost, strconv.Itoa(port))
port, err = getFreePort("0.0.0.0", DefaultTCPPort)
if err != nil {
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("config", "Configuration loading and saving")
)
var l = logger.DefaultLogger.NewFacility("config", "Configuration loading and saving")
+1 -1
View File
@@ -24,7 +24,7 @@ func ParseSize(s string) (Size, error) {
for i := 0; i < len(s) && (s[i] >= '0' && s[i] <= '9' || s[i] == '.' || s[i] == ','); i++ {
num = s[:i+1]
}
var i = len(num)
i := len(num)
for i < len(s) && s[i] == ' ' {
i++
}
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("connections", "Connection handling")
)
var l = logger.DefaultLogger.NewFacility("connections", "Connection handling")
+4 -2
View File
@@ -21,8 +21,10 @@ import (
"golang.org/x/time/rate"
)
var device1, device2, device3, device4 protocol.DeviceID
var dev1Conf, dev2Conf, dev3Conf, dev4Conf config.DeviceConfiguration
var (
device1, device2, device3, device4 protocol.DeviceID
dev1Conf, dev2Conf, dev3Conf, dev4Conf config.DeviceConfiguration
)
func init() {
device1, _ = protocol.DeviceIDFromString("AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ")
+6 -8
View File
@@ -11,14 +11,12 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
metricDeviceActiveConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "syncthing",
Subsystem: "connections",
Name: "active",
Help: "Number of currently active connections, per device. If value is 0, the device is disconnected.",
}, []string{"device"})
)
var metricDeviceActiveConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "syncthing",
Subsystem: "connections",
Name: "active",
Help: "Number of currently active connections, per device. If value is 0, the device is disconnected.",
}, []string{"device"})
func registerDeviceMetrics(deviceID string) {
// Register metrics for this device, so that counters & gauges are present even
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("backend", "The database backend")
)
var l = logger.DefaultLogger.NewFacility("backend", "The database backend")
+4 -2
View File
@@ -13,8 +13,10 @@ import (
"github.com/syncthing/syncthing/lib/protocol"
)
var f1, f2, f3 protocol.FileInfo
var folders = []string{"folder1", "folder2"}
var (
f1, f2, f3 protocol.FileInfo
folders = []string{"folder1", "folder2"}
)
func init() {
blocks := genBlocks(30)
-1
View File
@@ -159,7 +159,6 @@ func init() {
func TestUpdate0to3(t *testing.T) {
ldb, err := openJSONS("testdata/v0.14.45-update0to3.db.jsons")
if err != nil {
t.Fatal(err)
}
+1 -3
View File
@@ -10,9 +10,7 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("db", "The database layer")
)
var l = logger.DefaultLogger.NewFacility("db", "The database layer")
func shouldDebug() bool {
return l.ShouldDebug("db")
+1
View File
@@ -55,6 +55,7 @@ func globalList(t testing.TB, s *db.FileSet) []protocol.FileInfo {
})
return fs
}
func globalListPrefixed(t testing.TB, s *db.FileSet, prefix string) []db.FileInfoTruncated {
var fs []db.FileInfoTruncated
snap := snapshot(t, s)
+1 -3
View File
@@ -16,9 +16,7 @@ import (
"golang.org/x/net/proxy"
)
var (
noFallback = os.Getenv("ALL_PROXY_NO_FALLBACK") != ""
)
var noFallback = os.Getenv("ALL_PROXY_NO_FALLBACK") != ""
func init() {
proxy.RegisterDialerType("socks", socksDialerFunction)
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("discover", "Remote device discovery")
)
var l = logger.DefaultLogger.NewFacility("discover", "Remote device discovery")
+1
View File
@@ -244,6 +244,7 @@ type fakeAddressLister struct{}
func (*fakeAddressLister) ExternalAddresses() []string {
return []string{"tcp://0.0.0.0:22000"}
}
func (*fakeAddressLister) AllAddresses() []string {
return []string{"tcp://0.0.0.0:22000", "tcp://192.168.0.1:22000"}
}
+1 -3
View File
@@ -10,6 +10,4 @@ import (
liblogger "github.com/syncthing/syncthing/lib/logger"
)
var (
dl = liblogger.DefaultLogger.NewFacility("events", "Event generation and logging")
)
var dl = liblogger.DefaultLogger.NewFacility("events", "Event generation and logging")
-1
View File
@@ -81,7 +81,6 @@ func TestEventAfterSubscribe(t *testing.T) {
l.Log(DeviceConnected, "foo")
ev, err := s.Poll(timeout)
if err != nil {
t.Fatal("Unexpected error:", err)
}
+2 -2
View File
@@ -40,13 +40,13 @@ func (e basicFileInfo) Mode() FileMode {
}
// Set executable bits on files with executable extensions (.exe, .bat, etc).
if isWindowsExecutable(e.Name()) {
m |= 0111
m |= 0o111
}
// There is no user/group/others in Windows' read-only attribute, and
// all "w" bits are set if the file is not read-only. Do not send these
// group/others-writable bits to other devices in order to avoid
// unexpected world-writable files on other platforms.
m &^= 0022
m &^= 0o022
return FileMode(m)
}
+3 -3
View File
@@ -32,7 +32,7 @@ func readReparseTag(path string) (uint32, error) {
}
defer syscall.CloseHandle(h)
//https://docs.microsoft.com/windows/win32/api/winbase/ns-winbase-file_attribute_tag_info
// https://docs.microsoft.com/windows/win32/api/winbase/ns-winbase-file_attribute_tag_info
const fileAttributeTagInfo = 9
type FILE_ATTRIBUTE_TAG_INFO struct {
FileAttributes uint32
@@ -67,7 +67,7 @@ type dirJunctFileInfo struct {
func (fi *dirJunctFileInfo) Mode() os.FileMode {
// Simulate a directory and not a symlink; also set the execute
// bits so the directory can be traversed Unix-side.
return fi.FileInfo.Mode()&^junctionPointModeMask | os.ModeDir | 0111
return fi.FileInfo.Mode()&^junctionPointModeMask | os.ModeDir | 0o111
}
func (fi *dirJunctFileInfo) IsDir() bool {
@@ -89,7 +89,7 @@ func init() {
}
func (f *BasicFilesystem) underlyingLstat(name string) (os.FileInfo, error) {
var fi, err = os.Lstat(name)
fi, err := os.Lstat(name)
// There are cases where files are tagged as symlink, but they end up being
// something else. Make sure we properly handle those types.
+14 -14
View File
@@ -34,7 +34,7 @@ func TestChmodFile(t *testing.T) {
fs, dir := setup(t)
path := filepath.Join(dir, "file")
defer os.Chmod(path, 0666)
defer os.Chmod(path, 0o666)
fd, err := os.Create(path)
if err != nil {
@@ -42,19 +42,19 @@ func TestChmodFile(t *testing.T) {
}
fd.Close()
if err := os.Chmod(path, 0666); err != nil {
if err := os.Chmod(path, 0o666); err != nil {
t.Error(err)
}
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0666 {
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0o666 {
t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
}
if err := fs.Chmod("file", 0444); err != nil {
if err := fs.Chmod("file", 0o444); err != nil {
t.Error(err)
}
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0444 {
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0o444 {
t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
}
}
@@ -74,7 +74,7 @@ func TestChownFile(t *testing.T) {
fs, dir := setup(t)
path := filepath.Join(dir, "file")
defer os.Chmod(path, 0666)
defer os.Chmod(path, 0o666)
fd, err := os.Create(path)
if err != nil {
@@ -110,9 +110,9 @@ func TestChmodDir(t *testing.T) {
fs, dir := setup(t)
path := filepath.Join(dir, "dir")
mode := os.FileMode(0755)
mode := os.FileMode(0o755)
if build.IsWindows {
mode = os.FileMode(0777)
mode = os.FileMode(0o777)
}
defer os.Chmod(path, mode)
@@ -129,11 +129,11 @@ func TestChmodDir(t *testing.T) {
t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
}
if err := fs.Chmod("dir", 0555); err != nil {
if err := fs.Chmod("dir", 0o555); err != nil {
t.Error(err)
}
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0555 {
if stat, err := os.Stat(path); err != nil || stat.Mode()&os.ModePerm != 0o555 {
t.Errorf("wrong perm: %t %#o", err == nil, stat.Mode()&os.ModePerm)
}
}
@@ -221,7 +221,7 @@ func TestDirNames(t *testing.T) {
sort.Strings(testCases)
for _, sub := range testCases {
if err := os.Mkdir(filepath.Join(dir, sub), 0777); err != nil {
if err := os.Mkdir(filepath.Join(dir, sub), 0o777); err != nil {
t.Error(err)
}
}
@@ -256,7 +256,7 @@ func TestNames(t *testing.T) {
t.Errorf("incorrect %s != %s (%v)", stat.Name(), expected, err)
}
if err := fs.Mkdir("dir", 0777); err != nil {
if err := fs.Mkdir("dir", 0o777); err != nil {
t.Error(err)
}
@@ -286,7 +286,7 @@ func TestGlob(t *testing.T) {
filepath.Join("a", "best", "b"),
filepath.Join("a", "best", "c"),
} {
if err := fs.MkdirAll(dirToCreate, 0777); err != nil {
if err := fs.MkdirAll(dirToCreate, 0o777); err != nil {
t.Error(err)
}
}
@@ -572,7 +572,7 @@ func TestRel(t *testing.T) {
func TestXattr(t *testing.T) {
tfs, _ := setup(t)
if err := tfs.Mkdir("/test", 0755); err != nil {
if err := tfs.Mkdir("/test", 0o755); err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -198,7 +198,7 @@ func (f *BasicFilesystem) Remove(name string) error {
err = os.Remove(name)
if os.IsPermission(err) {
// Try to remove the read-only attribute and try again
if os.Chmod(name, 0600) == nil {
if os.Chmod(name, 0o600) == nil {
err = os.Remove(name)
}
}
+2 -2
View File
@@ -40,7 +40,7 @@ func testRealCase(t *testing.T, fsys Filesystem) {
testFs := newCaseFilesystem(fsys)
comps := []string{"Foo", "bar", "BAZ", "bAs"}
path := filepath.Join(comps...)
testFs.MkdirAll(filepath.Join(comps[:len(comps)-1]...), 0777)
testFs.MkdirAll(filepath.Join(comps[:len(comps)-1]...), 0o777)
fd, err := testFs.Create(path)
if err != nil {
t.Fatal(err)
@@ -93,7 +93,7 @@ func testRealCaseSensitive(t *testing.T, fsys Filesystem) {
names[0] = "foo"
names[1] = strings.ToUpper(names[0])
for _, n := range names {
if err := testFs.MkdirAll(n, 0777); err != nil {
if err := testFs.MkdirAll(n, 0o777); err != nil {
if IsErrCaseConflict(err) {
t.Skip("Filesystem is case-insensitive")
}
+1 -3
View File
@@ -10,9 +10,7 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("fs", "Filesystem access")
)
var l = logger.DefaultLogger.NewFacility("fs", "Filesystem access")
func init() {
logger.DefaultLogger.NewFacility("walkfs", "Filesystem access while walking")
+2
View File
@@ -30,6 +30,7 @@ func (fs *errorFilesystem) DirNames(_ string) ([]string, error) { return nil, fs
func (fs *errorFilesystem) GetXattr(_ string, _ XattrFilter) ([]protocol.Xattr, error) {
return nil, fs.err
}
func (fs *errorFilesystem) SetXattr(_ string, _ []protocol.Xattr, _ XattrFilter) error {
return fs.err
}
@@ -60,6 +61,7 @@ func (*errorFilesystem) SameFile(_, _ FileInfo) bool { return false }
func (fs *errorFilesystem) Watch(_ string, _ Matcher, _ context.Context, _ bool) (<-chan Event, <-chan error, error) {
return nil, nil, fs.err
}
func (fs *errorFilesystem) PlatformData(_ string, _, _ bool, _ XattrFilter) (protocol.PlatformData, error) {
return protocol.PlatformData{}, fs.err
}
+37 -37
View File
@@ -27,7 +27,7 @@ func TestFakeFS(t *testing.T) {
fs := newFakeFilesystem("/foo/bar/baz")
// MkdirAll
err := fs.MkdirAll("dira/dirb", 0755)
err := fs.MkdirAll("dira/dirb", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -37,7 +37,7 @@ func TestFakeFS(t *testing.T) {
}
// Mkdir
err = fs.Mkdir("dira/dirb/dirc", 0755)
err = fs.Mkdir("dira/dirb/dirc", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -190,7 +190,7 @@ type test struct {
}
func TestFakeFSCaseSensitive(t *testing.T) {
var tests = []test{
tests := []test{
{"Read", testFakeFSRead},
{"OpenFile", testFakeFSOpenFile},
{"RemoveAll", testFakeFSRemoveAll},
@@ -201,7 +201,7 @@ func TestFakeFSCaseSensitive(t *testing.T) {
{"DirNames", testDirNames},
{"FileName", testFakeFSFileName},
}
var filesystems = []testFS{
filesystems := []testFS{
{"fakeFS", newFakeFilesystem("/foo")},
}
@@ -214,7 +214,7 @@ func TestFakeFSCaseSensitive(t *testing.T) {
}
func TestFakeFSCaseInsensitive(t *testing.T) {
var tests = []test{
tests := []test{
{"Read", testFakeFSRead},
{"OpenFile", testFakeFSOpenFile},
{"RemoveAll", testFakeFSRemoveAll},
@@ -236,7 +236,7 @@ func TestFakeFSCaseInsensitive(t *testing.T) {
{"FileNameInsens", testFakeFSFileNameInsens},
}
var filesystems = []testFS{
filesystems := []testFS{
{"fakeFS", newFakeFilesystem("/foobar?insens=true")},
}
@@ -287,7 +287,7 @@ func runTests(t *testing.T, tests []test, filesystems []testFS) {
func testFakeFSCaseInsensitive(t *testing.T, fs Filesystem) {
bs1 := []byte("test")
err := fs.Mkdir("/fUbar", 0755)
err := fs.Mkdir("/fUbar", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -327,12 +327,12 @@ func testFakeFSCaseInsensitive(t *testing.T, fs Filesystem) {
}
func testFakeFSCaseInsensitiveMkdirAll(t *testing.T, fs Filesystem) {
err := fs.MkdirAll("/fOO/Bar/bAz", 0755)
err := fs.MkdirAll("/fOO/Bar/bAz", 0o755)
if err != nil {
t.Fatal(err)
}
fd, err := fs.OpenFile("/foo/BaR/BaZ/tESt", os.O_CREATE, 0644)
fd, err := fs.OpenFile("/foo/BaR/BaZ/tESt", os.O_CREATE, 0o644)
if err != nil {
t.Fatal(err)
}
@@ -430,7 +430,7 @@ func testFakeFSStatInsens(t *testing.T, fs Filesystem) {
}
func testFakeFSFileName(t *testing.T, fs Filesystem) {
var testCases = []struct {
testCases := []struct {
create string
open string
}{
@@ -458,7 +458,7 @@ func testFakeFSFileName(t *testing.T, fs Filesystem) {
}
func testFakeFSFileNameInsens(t *testing.T, fs Filesystem) {
var testCases = []struct {
testCases := []struct {
create string
open string
}{
@@ -486,7 +486,7 @@ func testFakeFSFileNameInsens(t *testing.T, fs Filesystem) {
}
func testFakeFSRename(t *testing.T, fs Filesystem) {
if err := fs.MkdirAll("/foo/bar/baz", 0755); err != nil {
if err := fs.MkdirAll("/foo/bar/baz", 0o755); err != nil {
t.Fatal(err)
}
@@ -500,7 +500,7 @@ func testFakeFSRename(t *testing.T, fs Filesystem) {
t.Errorf("rename to non-existent dir gave no error")
}
if err := fs.MkdirAll("/baz/bar/foo", 0755); err != nil {
if err := fs.MkdirAll("/baz/bar/foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -508,7 +508,7 @@ func testFakeFSRename(t *testing.T, fs Filesystem) {
t.Fatal(err)
}
var dirs = []struct {
dirs := []struct {
dir string
files []string
}{
@@ -531,11 +531,11 @@ func testFakeFSRename(t *testing.T, fs Filesystem) {
}
func testFakeFSRenameInsensitive(t *testing.T, fs Filesystem) {
if err := fs.MkdirAll("/baz/bar/foo", 0755); err != nil {
if err := fs.MkdirAll("/baz/bar/foo", 0o755); err != nil {
t.Fatal(err)
}
if err := fs.MkdirAll("/foO/baR/baZ", 0755); err != nil {
if err := fs.MkdirAll("/foO/baR/baZ", 0o755); err != nil {
t.Fatal(err)
}
@@ -550,7 +550,7 @@ func testFakeFSRenameInsensitive(t *testing.T, fs Filesystem) {
t.Fatal(err)
}
var dirs = []struct {
dirs := []struct {
dir string
files []string
}{
@@ -582,7 +582,7 @@ func testFakeFSRenameInsensitive(t *testing.T, fs Filesystem) {
}
func testFakeFSMkdir(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/foo", 0755); err != nil {
if err := fs.Mkdir("/foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -590,13 +590,13 @@ func testFakeFSMkdir(t *testing.T, fs Filesystem) {
t.Fatal(err)
}
if err := fs.Mkdir("/foo", 0755); err == nil {
if err := fs.Mkdir("/foo", 0o755); err == nil {
t.Errorf("got no error while creating existing directory")
}
}
func testFakeFSMkdirInsens(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/foo", 0755); err != nil {
if err := fs.Mkdir("/foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -604,37 +604,37 @@ func testFakeFSMkdirInsens(t *testing.T, fs Filesystem) {
t.Fatal(err)
}
if err := fs.Mkdir("/FOO", 0755); err == nil {
if err := fs.Mkdir("/FOO", 0o755); err == nil {
t.Errorf("got no error while creating existing directory")
}
}
func testFakeFSOpenFile(t *testing.T, fs Filesystem) {
fd, err := fs.OpenFile("foobar", os.O_RDONLY, 0664)
fd, err := fs.OpenFile("foobar", os.O_RDONLY, 0o664)
if err == nil {
fd.Close()
t.Fatalf("got no error opening a non-existing file")
}
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE, 0664)
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE, 0o664)
if err != nil {
t.Fatal(err)
}
fd.Close()
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0664)
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o664)
if err == nil {
fd.Close()
t.Fatalf("created an existing file while told not to")
}
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE, 0664)
fd, err = fs.OpenFile("foobar", os.O_RDWR|os.O_CREATE, 0o664)
if err != nil {
t.Fatal(err)
}
fd.Close()
fd, err = fs.OpenFile("foobar", os.O_RDWR, 0664)
fd, err = fs.OpenFile("foobar", os.O_RDWR, 0o664)
if err != nil {
t.Fatal(err)
}
@@ -642,31 +642,31 @@ func testFakeFSOpenFile(t *testing.T, fs Filesystem) {
}
func testFakeFSOpenFileInsens(t *testing.T, fs Filesystem) {
fd, err := fs.OpenFile("FooBar", os.O_RDONLY, 0664)
fd, err := fs.OpenFile("FooBar", os.O_RDONLY, 0o664)
if err == nil {
fd.Close()
t.Fatalf("got no error opening a non-existing file")
}
fd, err = fs.OpenFile("fOObar", os.O_RDWR|os.O_CREATE, 0664)
fd, err = fs.OpenFile("fOObar", os.O_RDWR|os.O_CREATE, 0o664)
if err != nil {
t.Fatal(err)
}
fd.Close()
fd, err = fs.OpenFile("fOoBaR", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0664)
fd, err = fs.OpenFile("fOoBaR", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o664)
if err == nil {
fd.Close()
t.Fatalf("created an existing file while told not to")
}
fd, err = fs.OpenFile("FoObAr", os.O_RDWR|os.O_CREATE, 0664)
fd, err = fs.OpenFile("FoObAr", os.O_RDWR|os.O_CREATE, 0o664)
if err != nil {
t.Fatal(err)
}
fd.Close()
fd, err = fs.OpenFile("FOOBAR", os.O_RDWR, 0664)
fd, err = fs.OpenFile("FOOBAR", os.O_RDWR, 0o664)
if err != nil {
t.Fatal(err)
}
@@ -674,7 +674,7 @@ func testFakeFSOpenFileInsens(t *testing.T, fs Filesystem) {
}
func testFakeFSRemoveAll(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/foo", 0755); err != nil {
if err := fs.Mkdir("/foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -702,7 +702,7 @@ func testFakeFSRemoveAll(t *testing.T, fs Filesystem) {
}
func testFakeFSRemoveAllInsens(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/Foo", 0755); err != nil {
if err := fs.Mkdir("/Foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -729,7 +729,7 @@ func testFakeFSRemoveAllInsens(t *testing.T, fs Filesystem) {
}
func testFakeFSRemove(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/Foo", 0755); err != nil {
if err := fs.Mkdir("/Foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -754,7 +754,7 @@ func testFakeFSRemove(t *testing.T, fs Filesystem) {
}
func testFakeFSRemoveInsens(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/Foo", 0755); err != nil {
if err := fs.Mkdir("/Foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -778,7 +778,7 @@ func testFakeFSRemoveInsens(t *testing.T, fs Filesystem) {
}
func testFakeFSSameFile(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/Foo", 0755); err != nil {
if err := fs.Mkdir("/Foo", 0o755); err != nil {
t.Fatal(err)
}
@@ -810,7 +810,7 @@ func testFakeFSSameFile(t *testing.T, fs Filesystem) {
}
func testFakeFSSameFileInsens(t *testing.T, fs Filesystem) {
if err := fs.Mkdir("/Foo", 0755); err != nil {
if err := fs.Mkdir("/Foo", 0o755); err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -104,7 +104,7 @@ func TestCanonicalize(t *testing.T) {
}
func TestFileModeString(t *testing.T) {
var fm FileMode = 0777
var fm FileMode = 0o777
exp := "-rwxrwxrwx"
if fm.String() != exp {
t.Fatalf("Got %v, expected %v", fm.String(), exp)
+2 -2
View File
@@ -23,10 +23,10 @@ func testWalkSkipSymlink(t *testing.T, fsType FilesystemType, uri string) {
fs := NewFilesystem(fsType, uri)
if err := fs.MkdirAll("target/foo", 0755); err != nil {
if err := fs.MkdirAll("target/foo", 0o755); err != nil {
t.Fatal(err)
}
if err := fs.Mkdir("towalk", 0755); err != nil {
if err := fs.Mkdir("towalk", 0o755); err != nil {
t.Fatal(err)
}
if err := fs.CreateSymlink("target", "towalk/symlink"); err != nil {
+2 -1
View File
@@ -7,10 +7,11 @@
package model
import (
"sort"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/rand"
"sort"
)
type blockPullReorderer interface {
+1 -3
View File
@@ -14,9 +14,7 @@ import (
"github.com/syncthing/syncthing/lib/protocol"
)
var (
someBlocks = []protocol.BlockInfo{{Offset: 1}, {Offset: 2}, {Offset: 3}}
)
var someBlocks = []protocol.BlockInfo{{Offset: 1}, {Offset: 2}, {Offset: 3}}
func Test_chunk(t *testing.T) {
type args struct {
+1 -3
View File
@@ -10,9 +10,7 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("model", "The root hub")
)
var l = logger.DefaultLogger.NewFacility("model", "The root hub")
func shouldDebug() bool {
return l.ShouldDebug("model")
+12 -11
View File
@@ -33,55 +33,56 @@ func TestDeviceDownloadState(t *testing.T) {
shouldHaveIndexesFrom []protocol.FileDownloadProgressUpdate
shouldNotHaveIndexesFrom []protocol.FileDownloadProgressUpdate
}{
{ //1
{ // 1
[]protocol.FileDownloadProgressUpdate{f1v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p2, f1v2p1, f1v2p2},
},
{ //2
{ // 2
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2},
[]protocol.FileDownloadProgressUpdate{f1v2p1, f1v2p2},
},
{ //3
{ // 3
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v1del},
nil,
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1, f1v2p2}},
{ //4
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1, f1v2p2},
},
{ // 4
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2del},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2},
[]protocol.FileDownloadProgressUpdate{f1v2p1, f1v2p2},
},
{ //5
{ // 5
// v2 replaces old v1 data
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1},
[]protocol.FileDownloadProgressUpdate{f1v2p1},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p2},
},
{ //6
{ // 6
// v1 delete on v2 data does nothing
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1, f1v1del},
[]protocol.FileDownloadProgressUpdate{f1v2p1},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p2},
},
{ //7
{ // 7
// v2 replacees v1, v2 gets deleted, and v2 part 2 gets added.
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1, f1v2del, f1v2p2},
[]protocol.FileDownloadProgressUpdate{f1v2p2},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f1v1p2, f1v2p1},
},
// Multiple files in one go
{ //8
{ // 8
[]protocol.FileDownloadProgressUpdate{f1v1p1, f2v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f2v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p2, f2v1p2},
},
{ //9
{ // 9
[]protocol.FileDownloadProgressUpdate{f1v1p1, f2v1p1, f2v1del},
[]protocol.FileDownloadProgressUpdate{f1v1p1},
[]protocol.FileDownloadProgressUpdate{f2v1p1, f2v1p1},
},
{ //10
{ // 10
[]protocol.FileDownloadProgressUpdate{f1v1p1, f2v1del, f2v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p1, f2v1p1},
[]protocol.FileDownloadProgressUpdate{f1v1p2, f2v1p2},
+1 -1
View File
@@ -448,7 +448,7 @@ func (s *indexHandler) receive(fs []protocol.FileInfo, update bool, op string, p
seq := fset.Sequence(deviceID)
// Check that the sequence we get back is what we put in...
if lastSequence > 0 && seq != lastSequence {
if lastSequence > 0 && len(fs) > 0 && seq != lastSequence {
s.logSequenceAnomaly("unexpected sequence after update", map[string]any{
"prevSeq": prevSequence,
"lastSeq": lastSequence,
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("nat", "NAT discovery and port mapping")
)
var l = logger.DefaultLogger.NewFacility("nat", "NAT discovery and port mapping")
+1 -1
View File
@@ -101,7 +101,7 @@ func (w *AtomicWriter) Close() error {
// On Windows, we might not be allowed to rename over the file
// because it's read-only. Get us some write permissions and try
// again.
_ = w.fs.Chmod(w.path, 0644)
_ = w.fs.Chmod(w.path, 0o644)
err = w.fs.Rename(w.next.Name(), w.path)
}
if err != nil {
+5 -4
View File
@@ -17,7 +17,7 @@ func TestCreateAtomicCreate(t *testing.T) {
os.RemoveAll("testdata")
defer os.RemoveAll("testdata")
if err := os.Mkdir("testdata", 0755); err != nil {
if err := os.Mkdir("testdata", 0o755); err != nil {
t.Fatal(err)
}
@@ -52,10 +52,11 @@ func TestCreateAtomicCreate(t *testing.T) {
}
func TestCreateAtomicReplace(t *testing.T) {
testCreateAtomicReplace(t, 0666)
testCreateAtomicReplace(t, 0o666)
}
func TestCreateAtomicReplaceReadOnly(t *testing.T) {
testCreateAtomicReplace(t, 0444) // windows compatible read-only bits
testCreateAtomicReplace(t, 0o444) // windows compatible read-only bits
}
func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
@@ -66,7 +67,7 @@ func testCreateAtomicReplace(t *testing.T, oldPerms os.FileMode) {
os.RemoveAll(testdir)
if err := os.Mkdir(testdir, 0755); err != nil {
if err := os.Mkdir(testdir, 0o755); err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -38,7 +38,7 @@ func TestTempFilePermissions(t *testing.T) {
// The temp file should have 0600 permissions at the most, or we have a
// security problem in CreateAtomic.
t.Logf("Got 0%03o", info.Mode())
if info.Mode()&^0600 != 0 {
if info.Mode()&^0o600 != 0 {
t.Errorf("Permission 0%03o is too generous", info.Mode())
}
}
+3 -3
View File
@@ -84,14 +84,14 @@ func Copy(method fs.CopyRangeMethod, src, dst fs.Filesystem, from, to string) (e
func withPreparedTarget(filesystem fs.Filesystem, from, to string, f func() error) error {
// Make sure the destination directory is writeable
toDir := filepath.Dir(to)
if info, err := filesystem.Stat(toDir); err == nil && info.IsDir() && info.Mode()&0200 == 0 {
filesystem.Chmod(toDir, 0755)
if info, err := filesystem.Stat(toDir); err == nil && info.IsDir() && info.Mode()&0o200 == 0 {
filesystem.Chmod(toDir, 0o755)
defer filesystem.Chmod(toDir, info.Mode())
}
// On Windows, make sure the destination file is writeable (or we can't delete it)
if build.IsWindows {
filesystem.Chmod(to, 0666)
filesystem.Chmod(to, 0o666)
if !strings.EqualFold(from, to) {
err := filesystem.Remove(to)
if err != nil && !fs.IsNotExist(err) {
+5 -3
View File
@@ -16,8 +16,10 @@ import (
"github.com/syncthing/syncthing/lib/fs"
)
var rand uint32
var randmu sync.Mutex
var (
rand uint32
randmu sync.Mutex
)
func reseed() uint32 {
return uint32(time.Now().UnixNano() + int64(os.Getpid()))
@@ -48,7 +50,7 @@ func TempFile(filesystem fs.Filesystem, dir, prefix string) (f fs.File, err erro
nconflict := 0
for i := 0; i < 10000; i++ {
name := filepath.Join(dir, prefix+nextSuffix())
f, err = filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate|fs.OptExclusive, 0600)
f, err = filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate|fs.OptExclusive, 0o600)
if fs.IsExist(err) {
if nconflict++; nconflict > 10 {
randmu.Lock()
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("pmp", "NAT-PMP discovery and port mapping")
)
var l = logger.DefaultLogger.NewFacility("pmp", "NAT-PMP discovery and port mapping")
+2 -2
View File
@@ -317,10 +317,10 @@ func PermsEqual(a, b uint32) bool {
if build.IsWindows {
// There is only writeable and read only, represented for user, group
// and other equally. We only compare against user.
return a&0600 == b&0600
return a&0o600 == b&0o600
}
// All bits count
return a&0777 == b&0777
return a&0o777 == b&0o777
}
// BlocksEqual returns true when the two files have identical block lists.
+1 -3
View File
@@ -6,6 +6,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("protocol", "The BEP protocol")
)
var l = logger.DefaultLogger.NewFacility("protocol", "The BEP protocol")
+15 -13
View File
@@ -4,19 +4,21 @@ package protocol
import "testing"
var formatted = "P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"
var formatCases = []string{
"P56IOI-7MZJNU-2IQGDR-EYDM2M-GTMGL3-BXNPQ6-W5BTBB-Z4TJXZ-WICQ",
"P56IOI-7MZJNU2Y-IQGDR-EYDM2M-GTI-MGL3-BXNPQ6-W5BM-TBB-Z4TJXZ-WICQ2",
"P56IOI7 MZJNU2I QGDREYD M2MGTMGL 3BXNPQ6W 5BTB BZ4T JXZWICQ",
"P56IOI7 MZJNU2Y IQGDREY DM2MGTI MGL3BXN PQ6W5BM TBBZ4TJ XZWICQ2",
"P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ",
"p56ioi7mzjnu2iqgdreydm2mgtmgl3bxnpq6w5btbbz4tjxzwicq",
"P56IOI7MZJNU2YIQGDREYDM2MGTIMGL3BXNPQ6W5BMTBBZ4TJXZWICQ2",
"P561017MZJNU2YIQGDREYDM2MGTIMGL3BXNPQ6W5BMT88Z4TJXZWICQ2",
"p56ioi7mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmtbbz4tjxzwicq2",
"p561017mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmt88z4tjxzwicq2",
}
var (
formatted = "P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"
formatCases = []string{
"P56IOI-7MZJNU-2IQGDR-EYDM2M-GTMGL3-BXNPQ6-W5BTBB-Z4TJXZ-WICQ",
"P56IOI-7MZJNU2Y-IQGDR-EYDM2M-GTI-MGL3-BXNPQ6-W5BM-TBB-Z4TJXZ-WICQ2",
"P56IOI7 MZJNU2I QGDREYD M2MGTMGL 3BXNPQ6W 5BTB BZ4T JXZWICQ",
"P56IOI7 MZJNU2Y IQGDREY DM2MGTI MGL3BXN PQ6W5BM TBBZ4TJ XZWICQ2",
"P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ",
"p56ioi7mzjnu2iqgdreydm2mgtmgl3bxnpq6w5btbbz4tjxzwicq",
"P56IOI7MZJNU2YIQGDREYDM2MGTIMGL3BXNPQ6W5BMTBBZ4TJXZWICQ2",
"P561017MZJNU2YIQGDREYDM2MGTIMGL3BXNPQ6W5BMT88Z4TJXZWICQ2",
"p56ioi7mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmtbbz4tjxzwicq2",
"p561017mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmt88z4tjxzwicq2",
}
)
func TestFormatDeviceID(t *testing.T) {
for i, tc := range formatCases {
+28 -20
View File
@@ -212,38 +212,44 @@ func (e encryptedConnection) Request(ctx context.Context, req *Request) ([]byte,
if !ok {
return e.conn.Request(ctx, req)
}
fileKey := e.keyGen.FileKey(req.Name, folderKey)
// Encrypt / adjust the request parameters.
origSize := req.Size
origName := req.Name
if req.Size < minPaddedSize {
encSize := req.Size
if encSize < minPaddedSize {
// Make a request for minPaddedSize data instead of the smaller
// block. We'll chop of the extra data later.
req.Size = minPaddedSize
encSize = minPaddedSize
}
encSize += blockOverhead
encName := encryptName(req.Name, folderKey)
encOffset := req.Offset + int64(req.BlockNo*blockOverhead)
encSize := req.Size + blockOverhead
encHash := encryptBlockHash(req.Hash, req.Offset, fileKey)
// Perform that request, getting back an encrypted block.
req.Name = encName
req.Offset = encOffset
req.Size = encSize
bs, err := e.conn.Request(ctx, req)
encReq := &Request{
ID: req.ID,
Folder: req.Folder,
Name: encName,
Offset: encOffset,
Size: encSize,
Hash: encHash,
BlockNo: req.BlockNo,
}
bs, err := e.conn.Request(ctx, encReq)
if err != nil {
return nil, err
}
// Return the decrypted block (or an error if it fails decryption)
fileKey := e.keyGen.FileKey(origName, folderKey)
bs, err = DecryptBytes(bs, fileKey)
if err != nil {
return nil, err
}
return bs[:origSize], nil
return bs[:req.Size], nil
}
func (e encryptedConnection) DownloadProgress(ctx context.Context, dp *DownloadProgress) {
@@ -327,15 +333,7 @@ func encryptFileInfo(keyGen *KeyGenerator, fi FileInfo, folderKey *[keySize]byte
b.Size = minPaddedSize
}
size := b.Size + blockOverhead
// The offset goes into the encrypted block hash as additional data,
// essentially mixing in with the nonce. This means a block hash
// remains stable for the same data at the same offset, but doesn't
// reveal the existence of identical data blocks at other offsets.
var additional [8]byte
binary.BigEndian.PutUint64(additional[:], uint64(b.Offset))
hash := encryptDeterministic(b.Hash, fileKey, additional[:])
hash := encryptBlockHash(b.Hash, b.Offset, fileKey)
blocks[i] = BlockInfo{
Hash: hash,
Offset: offset,
@@ -374,6 +372,16 @@ func encryptFileInfo(keyGen *KeyGenerator, fi FileInfo, folderKey *[keySize]byte
return enc
}
func encryptBlockHash(hash []byte, offset int64, fileKey *[keySize]byte) []byte {
// The offset goes into the encrypted block hash as additional data,
// essentially mixing in with the nonce. This means a block hash
// remains stable for the same data at the same offset, but doesn't
// reveal the existence of identical data blocks at other offsets.
var additional [8]byte
binary.BigEndian.PutUint64(additional[:], uint64(offset))
return encryptDeterministic(hash, fileKey, additional[:])
}
func decryptFileInfos(keyGen *KeyGenerator, files []FileInfo, folderKey *[keySize]byte) error {
for i, fi := range files {
decFI, err := DecryptFileInfo(keyGen, fi, folderKey)
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("rc", "Remote control package")
)
var l = logger.DefaultLogger.NewFacility("rc", "Remote control package")
+1 -3
View File
@@ -6,6 +6,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("relay", "")
)
var l = logger.DefaultLogger.NewFacility("relay", "")
+5 -3
View File
@@ -29,9 +29,11 @@ type header struct {
messageLength int32
}
type Ping struct{}
type Pong struct{}
type RelayFull struct{}
type (
Ping struct{}
Pong struct{}
RelayFull struct{}
)
type JoinRelayRequest struct {
Token string
+9
View File
@@ -60,6 +60,7 @@ func (o *header) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *header) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.magic = u.UnmarshalUint32()
o.messageType = int32(u.UnmarshalUint32())
@@ -81,6 +82,7 @@ struct Ping {
func (Ping) XDRSize() int {
return 0
}
func (Ping) MarshalXDR() ([]byte, error) {
return nil, nil
}
@@ -115,6 +117,7 @@ struct Pong {
func (Pong) XDRSize() int {
return 0
}
func (Pong) MarshalXDR() ([]byte, error) {
return nil, nil
}
@@ -149,6 +152,7 @@ struct RelayFull {
func (RelayFull) XDRSize() int {
return 0
}
func (RelayFull) MarshalXDR() ([]byte, error) {
return nil, nil
}
@@ -215,6 +219,7 @@ func (o *JoinRelayRequest) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *JoinRelayRequest) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.Token = u.UnmarshalString()
return u.Error
@@ -269,6 +274,7 @@ func (o *JoinSessionRequest) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *JoinSessionRequest) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.Key = u.UnmarshalBytesMax(32)
return u.Error
@@ -325,6 +331,7 @@ func (o *Response) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *Response) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.Code = int32(u.UnmarshalUint32())
o.Message = u.UnmarshalString()
@@ -380,6 +387,7 @@ func (o *ConnectRequest) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *ConnectRequest) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.ID = u.UnmarshalBytesMax(32)
return u.Error
@@ -462,6 +470,7 @@ func (o *SessionInvitation) UnmarshalXDR(bs []byte) error {
u := &xdr.Unmarshaller{Data: bs}
return o.UnmarshalXDRFrom(u)
}
func (o *SessionInvitation) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
o.From = u.UnmarshalBytesMax(32)
o.Key = u.UnmarshalBytesMax(32)
+47 -24
View File
@@ -27,43 +27,67 @@ var blocksTestData = []struct {
hash []string
weakhash []uint32
}{
{[]byte(""), 1024, []string{
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
{
[]byte(""), 1024,
[]string{
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
[]uint32{0},
},
{[]byte("contents"), 1024, []string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8"},
{
[]byte("contents"), 1024,
[]string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8",
},
[]uint32{0x0f3a036f},
},
{[]byte("contents"), 9, []string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8"},
{
[]byte("contents"), 9,
[]string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8",
},
[]uint32{0x0f3a036f},
},
{[]byte("contents"), 8, []string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8"},
{
[]byte("contents"), 8,
[]string{
"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8",
},
[]uint32{0x0f3a036f},
},
{[]byte("contents"), 7, []string{
"ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73",
"043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89"},
{
[]byte("contents"), 7,
[]string{
"ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73",
"043a718774c572bd8a25adbeb1bfcd5c0256ae11cecf9f9c3f925d0e52beaf89",
},
[]uint32{0x0bcb02fc, 0x00740074},
},
{[]byte("contents"), 3, []string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3",
"44ad63f60af0f6db6fdde6d5186ef78176367df261fa06be3079b6c80c8adba4"},
{
[]byte("contents"), 3,
[]string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3",
"44ad63f60af0f6db6fdde6d5186ef78176367df261fa06be3079b6c80c8adba4",
},
[]uint32{0x02780141, 0x02970148, 0x015d00e8},
},
{[]byte("conconts"), 3, []string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"44ad63f60af0f6db6fdde6d5186ef78176367df261fa06be3079b6c80c8adba4"},
{
[]byte("conconts"), 3,
[]string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"44ad63f60af0f6db6fdde6d5186ef78176367df261fa06be3079b6c80c8adba4",
},
[]uint32{0x02780141, 0x02780141, 0x015d00e8},
},
{[]byte("contenten"), 3, []string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3"},
{
[]byte("contenten"), 3,
[]string{
"1143da2bc54c495c4be31d3868785d39ffdfd56df5668f0645d8f14d47647952",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3",
"e4432baa90819aaef51d2a7f8e148bf7e679610f3173752fabb4dcb2d0f418d3",
},
[]uint32{0x02780141, 0x02970148, 0x02970148},
},
}
@@ -72,7 +96,6 @@ func TestBlocks(t *testing.T) {
for testNo, test := range blocksTestData {
buf := bytes.NewBuffer(test.data)
blocks, err := Blocks(context.TODO(), buf, test.blocksize, -1, nil, true)
if err != nil {
t.Fatal(err)
}
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("scanner", "File change detection and hashing")
)
var l = logger.DefaultLogger.NewFacility("scanner", "File change detection and hashing")
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("stats", "Persistent device and folder statistics")
)
var l = logger.DefaultLogger.NewFacility("stats", "Persistent device and folder statistics")
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("stun", "STUN functionality")
)
var l = logger.DefaultLogger.NewFacility("stun", "STUN functionality")
+1 -3
View File
@@ -10,9 +10,7 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("app", "Main run facility")
)
var l = logger.DefaultLogger.NewFacility("app", "Main run facility")
func shouldDebug() bool {
return l.ShouldDebug("app")
+4 -2
View File
@@ -33,7 +33,7 @@ func EnsureDir(dir string, mode fs.FileMode) error {
// Apparently the stat may fail even though the mkdirall passed. If it
// does, we'll just assume things are in order and let other things
// fail (like loading or creating the config...).
currentMode := fi.Mode() & 0777
currentMode := fi.Mode() & 0o777
if currentMode != mode {
err := fs.Chmod(".", mode)
// This can fail on crappy filesystems, nothing we can do about it.
@@ -63,6 +63,8 @@ func DefaultConfig(path string, myID protocol.DeviceID, evLogger events.Logger,
if skipPortProbing {
l.Infoln("Using default network port numbers instead of probing for free ports")
// Record address override initially
newCfg.GUI.RawAddress = newCfg.GUI.Address()
} else if err := newCfg.ProbeFreePorts(); err != nil {
return nil, err
}
@@ -139,7 +141,7 @@ func copyFile(src, dst string) error {
return err
}
if err := os.WriteFile(dst, bs, 0600); err != nil {
if err := os.WriteFile(dst, bs, 0o600); err != nil {
// Attempt to clean up
os.Remove(dst)
return err
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("upgrade", "Binary upgrades")
)
var l = logger.DefaultLogger.NewFacility("upgrade", "Binary upgrades")
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("upnp", "UPnP discovery and port mapping")
)
var l = logger.DefaultLogger.NewFacility("upnp", "UPnP discovery and port mapping")
+1 -3
View File
@@ -210,7 +210,6 @@ USER-AGENT: syncthing/%s
proto = "udp6"
}
socket, err := net.ListenMulticastUDP(proto, intf, &net.UDPAddr{IP: ssdp.IP})
if err != nil {
if runtime.GOOS == "windows" && ip6 {
// Requires https://github.com/golang/go/issues/63529 to be fixed.
@@ -257,7 +256,7 @@ loop:
if e, ok := err.(net.Error); ok && e.Timeout() {
continue // continue reading
}
l.Infoln("UPnP read:", err) //legitimate error, not a timeout.
l.Infoln("UPnP read:", err) // legitimate error, not a timeout.
break
}
@@ -411,7 +410,6 @@ func localIPv4Fallback(ctx context.Context, url *url.URL) (net.IP, error) {
defer cancel()
conn, err := dialer.DialContext(timeoutCtx, "udp4", url.Host)
if err != nil {
return nil, err
}
+2 -4
View File
@@ -13,8 +13,7 @@ import (
)
func TestExternalIPParsing(t *testing.T) {
soapResponse :=
[]byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
soapResponse := []byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewExternalIPAddress>1.2.3.4</NewExternalIPAddress>
@@ -34,8 +33,7 @@ func TestExternalIPParsing(t *testing.T) {
}
func TestSoapFaultParsing(t *testing.T) {
soapResponse :=
[]byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
soapResponse := []byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("ur", "Usage reporting")
)
var l = logger.DefaultLogger.NewFacility("ur", "Usage reporting")
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("versioner", "File versioning")
)
var l = logger.DefaultLogger.NewFacility("versioner", "File versioning")
+2 -2
View File
@@ -27,7 +27,7 @@ import (
// └── remove21
// └── remove22
func TestEmptyDirs(t *testing.T) {
var paths = []struct {
paths := []struct {
path string
isFile bool
}{
@@ -44,7 +44,7 @@ func TestEmptyDirs(t *testing.T) {
{"remove2/remove21/remove22", false},
}
var expected = []string{
expected := []string{
"remove2/remove21/remove22",
"remove2/remove21",
"remove2",
+2 -2
View File
@@ -81,10 +81,10 @@ func prepForRemoval(t *testing.T, file string) {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(file, []byte("hello\n"), 0644); err != nil {
if err := os.WriteFile(file, []byte("hello\n"), 0o644); err != nil {
t.Fatal(err)
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ type simple struct {
}
func newSimple(cfg config.FolderConfiguration) Versioner {
var keep, err = strconv.Atoi(cfg.Versioning.Params["keep"])
keep, err := strconv.Atoi(cfg.Versioning.Params["keep"])
cleanoutDays, _ := strconv.Atoi(cfg.Versioning.Params["cleanoutDays"])
// On error we default to 0, "do not clean out the versioned items"
+1 -1
View File
@@ -134,7 +134,7 @@ func TestCreateVersionPath(t *testing.T) {
// Create a test dir and file
tmpDir := t.TempDir()
if err := os.WriteFile(filepath.Join(tmpDir, archiveFile), []byte("sup"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, archiveFile), []byte("sup"), 0o644); err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -182,7 +182,7 @@ func readFile(t *testing.T, filesystem fs.Filesystem, name string) string {
}
func writeFile(t *testing.T, filesystem fs.Filesystem, name, content string) {
fd, err := filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate, 0777)
fd, err := filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate, 0o777)
if err != nil {
t.Fatal(err)
}
@@ -213,7 +213,7 @@ func TestTrashcanCleanOut(t *testing.T) {
v := newTrashcan(cfg)
var testcases = map[string]bool{
testcases := map[string]bool{
".stversions/file1": false,
".stversions/file2": true,
".stversions/keep1/file1": false,
@@ -229,7 +229,7 @@ func TestTrashcanCleanOut(t *testing.T) {
t.Run("trashcan versioner trashcan clean up", func(t *testing.T) {
oldTime := time.Now().Add(-8 * 24 * time.Hour)
for file, shouldRemove := range testcases {
fs.MkdirAll(filepath.Dir(file), 0777)
fs.MkdirAll(filepath.Dir(file), 0o777)
writeFile(t, fs, file, "some content")
+1 -3
View File
@@ -10,6 +10,4 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
var (
l = logger.DefaultLogger.NewFacility("watchaggregator", "Filesystem event watcher")
)
var l = logger.DefaultLogger.NewFacility("watchaggregator", "Filesystem event watcher")
+4 -4
View File
@@ -23,8 +23,10 @@ import (
"github.com/chmduquesne/rollinghash/buzhash64"
)
const testFile = "../model/testdata/tmpfile"
const size = 128 << 10
const (
testFile = "../model/testdata/tmpfile"
size = 128 << 10
)
func BenchmarkFind1MFile(b *testing.B) {
b.ReportAllocs()
@@ -96,7 +98,6 @@ func BenchmarkBlock(b *testing.B) {
bbb.SetBytes(testSize)
bbb.ReportAllocs()
})
})
}
}
@@ -144,7 +145,6 @@ func BenchmarkRoll(b *testing.B) {
bbb.SetBytes(testSize)
bbb.ReportAllocs()
})
})
}
}
-1
View File
@@ -65,5 +65,4 @@ func walk(w *csv.Writer, prefix string, data interface{}) {
})
}
}
}
+1 -1
View File
@@ -119,7 +119,7 @@ func main() {
bs := readAll(htmlFile)
bs = authorsRe.ReplaceAll(bs, []byte("id=\"contributor-list\">\n"+replacement+"\n </div>"))
if err := os.WriteFile(htmlFile, bs, 0644); err != nil {
if err := os.WriteFile(htmlFile, bs, 0o644); err != nil {
log.Fatal(err)
}
+6 -4
View File
@@ -21,9 +21,11 @@ import (
"golang.org/x/net/html"
)
var trans = make(map[string]interface{})
var attrRe = regexp.MustCompile(`\{\{\s*'([^']+)'\s+\|\s+translate\s*\}\}`)
var attrReCond = regexp.MustCompile(`\{\{.+\s+\?\s+'([^']+)'\s+:\s+'([^']+)'\s+\|\s+translate\s*\}\}`)
var (
trans = make(map[string]interface{})
attrRe = regexp.MustCompile(`\{\{\s*'([^']+)'\s+\|\s+translate\s*\}\}`)
attrReCond = regexp.MustCompile(`\{\{.+\s+\?\s+'([^']+)'\s+:\s+'([^']+)'\s+\|\s+translate\s*\}\}`)
)
// Find both $translate.instant("…") and $translate.instant("…",…) in JS.
// Consider single quote variants too.
@@ -204,7 +206,7 @@ func main() {
}
fd.Close()
var guiDir = os.Args[2]
guiDir := os.Args[2]
filepath.Walk(guiDir, walkerFor(guiDir))
collectThemes(guiDir)
+1 -1
View File
@@ -23,7 +23,7 @@ func TestCLIReset(t *testing.T) {
// Create directories that reset will remove
for _, dir := range dirs {
err := os.Mkdir(dir, 0755)
err := os.Mkdir(dir, 0o755)
if err != nil && !os.IsExist(err) {
t.Fatal(err)
}
+23 -23
View File
@@ -87,7 +87,7 @@ func TestConflictsDefault(t *testing.T) {
t.Fatal(err)
}
fd, err = os.OpenFile("s1/testfile.txt", os.O_WRONLY|os.O_APPEND, 0644)
fd, err = os.OpenFile("s1/testfile.txt", os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
t.Fatal(err)
}
@@ -100,7 +100,7 @@ func TestConflictsDefault(t *testing.T) {
t.Fatal(err)
}
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0644)
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
t.Fatal(err)
}
@@ -150,7 +150,7 @@ func TestConflictsDefault(t *testing.T) {
t.Fatal(err)
}
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0644)
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
t.Fatal(err)
}
@@ -204,37 +204,37 @@ func TestConflictsInitialMerge(t *testing.T) {
t.Fatal(err)
}
err = os.Mkdir("s1", 0755)
err = os.Mkdir("s1", 0o755)
if err != nil {
t.Fatal(err)
}
err = os.Mkdir("s2", 0755)
err = os.Mkdir("s2", 0o755)
if err != nil {
t.Fatal(err)
}
// File 1 is a conflict
err = os.WriteFile("s1/file1", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file1", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0644)
err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0o644)
if err != nil {
t.Fatal(err)
}
// File 2 exists on s1 only
err = os.WriteFile("s1/file2", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file2", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
// File 3 exists on s2 only
err = os.WriteFile("s2/file3", []byte("goodbye\n"), 0644)
err = os.WriteFile("s2/file3", []byte("goodbye\n"), 0o644)
if err != nil {
t.Fatal(err)
}
@@ -303,26 +303,26 @@ func TestConflictsIndexReset(t *testing.T) {
t.Fatal(err)
}
err = os.Mkdir("s1", 0755)
err = os.Mkdir("s1", 0o755)
if err != nil {
t.Fatal(err)
}
err = os.Mkdir("s2", 0755)
err = os.Mkdir("s2", 0o755)
if err != nil {
t.Fatal(err)
}
// Three files on s1
err = os.WriteFile("s1/file1", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file1", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("s1/file2", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file2", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("s2/file3", []byte("hello\n"), 0644)
err = os.WriteFile("s2/file3", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
@@ -370,7 +370,7 @@ func TestConflictsIndexReset(t *testing.T) {
// locally after we rest the index, unless we have a fix for that.
for i := 0; i < 5; i++ {
err = os.WriteFile("s2/file2", []byte("hello1\n"), 0644)
err = os.WriteFile("s2/file2", []byte("hello1\n"), 0o644)
if err != nil {
t.Fatal(err)
}
@@ -392,7 +392,7 @@ func TestConflictsIndexReset(t *testing.T) {
// s1/file1 (remote) changes while receiver is down
err = os.WriteFile("s1/file1", []byte("goodbye\n"), 0644)
err = os.WriteFile("s1/file1", []byte("goodbye\n"), 0o644)
if err != nil {
t.Fatal(err)
}
@@ -405,7 +405,7 @@ func TestConflictsIndexReset(t *testing.T) {
// s2/file2 (local) changes while receiver is down
err = os.WriteFile("s2/file2", []byte("goodbye\n"), 0644)
err = os.WriteFile("s2/file2", []byte("goodbye\n"), 0o644)
if err != nil {
t.Fatal(err)
}
@@ -456,33 +456,33 @@ func TestConflictsSameContent(t *testing.T) {
t.Fatal(err)
}
err = os.Mkdir("s1", 0755)
err = os.Mkdir("s1", 0o755)
if err != nil {
t.Fatal(err)
}
err = os.Mkdir("s2", 0755)
err = os.Mkdir("s2", 0o755)
if err != nil {
t.Fatal(err)
}
// Two files on s1
err = os.WriteFile("s1/file1", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file1", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("s1/file2", []byte("hello\n"), 0644)
err = os.WriteFile("s1/file2", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
// Two files on s2, content differs in file1 only, timestamps differ on both.
err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0644)
err = os.WriteFile("s2/file1", []byte("goodbye\n"), 0o644)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile("s2/file2", []byte("hello\n"), 0644)
err = os.WriteFile("s2/file2", []byte("hello\n"), 0o644)
if err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -31,7 +31,7 @@ func TestRescanWithDelay(t *testing.T) {
}
log.Println("Generating .stignore...")
err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644)
err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0o644)
if err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -90,14 +90,14 @@ func testFileTypeChange(t *testing.T) {
// A directory that we will replace with a file later
err = os.Mkdir("s1/emptyDirToReplace", 0755)
err = os.Mkdir("s1/emptyDirToReplace", 0o755)
if err != nil {
t.Fatal(err)
}
// A directory with files that we will replace with a file later
err = os.Mkdir("s1/dirToReplace", 0755)
err = os.Mkdir("s1/dirToReplace", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -141,7 +141,7 @@ func testFileTypeChange(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = os.Mkdir("s1/fileToReplace", 0755)
err = os.Mkdir("s1/fileToReplace", 0o755)
if err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -223,7 +223,7 @@ func setupAPIBench() *rc.Process {
panic(err)
}
err = os.WriteFile("s1/knownfile", []byte("somedatahere"), 0644)
err = os.WriteFile("s1/knownfile", []byte("somedatahere"), 0o644)
if err != nil {
panic(err)
}
+3 -3
View File
@@ -35,7 +35,7 @@ func TestIgnores(t *testing.T) {
files := []string{"f1", "f2", "f3", "f4", "f11", "f12", "f13", "f14", "d1/f1.TXT"}
for _, dir := range dirs {
err := os.Mkdir(filepath.Join("s1", dir), 0755)
err := os.Mkdir(filepath.Join("s1", dir), 0o755)
if err != nil {
t.Fatal(err)
}
@@ -68,7 +68,7 @@ func TestIgnores(t *testing.T) {
err = os.WriteFile("s1/.stignore",
[]byte("f1*\nf2\nd1*\nd2\ns1*\ns2\n(?i)*.txt"), // [fds][34] only non-ignored items
0644)
0o644)
if err != nil {
t.Fatal(err)
}
@@ -91,7 +91,7 @@ func TestIgnores(t *testing.T) {
// Change the pattern to include some of the files and dirs previously ignored
time.Sleep(1100 * time.Millisecond)
err = os.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0644)
err = os.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0o644)
// Rescan and verify that we see them
+1 -1
View File
@@ -90,7 +90,7 @@ func TestOverride(t *testing.T) {
log.Println("Changing file on sendRecv side...")
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0644)
fd, err = os.OpenFile("s2/testfile.txt", os.O_WRONLY|os.O_APPEND, 0o644)
if err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -31,7 +31,7 @@ func TestRescanInParallel(t *testing.T) {
}
log.Println("Generating .stignore...")
err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0644)
err = os.WriteFile("s1/.stignore", []byte("some ignore data\n"), 0o644)
if err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -28,7 +28,7 @@ func TestReset(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := os.Mkdir("s1", 0755); err != nil {
if err := os.Mkdir("s1", 0o755); err != nil {
t.Fatal(err)
}
@@ -53,7 +53,7 @@ func TestReset(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := os.Mkdir("s1", 0755); err != nil {
if err := os.Mkdir("s1", 0o755); err != nil {
t.Fatal(err)
}
if fd, err := os.Create("s1/.stfolder"); err != nil {
@@ -146,7 +146,7 @@ func createFiles(t *testing.T) int {
const n = 8
for i := 0; i < n; i++ {
file := fmt.Sprintf("f%d", i)
if err := os.WriteFile(filepath.Join("s1", file), []byte("data"), 0644); err != nil {
if err := os.WriteFile(filepath.Join("s1", file), []byte("data"), 0o644); err != nil {
t.Fatal(err)
}
}
+3 -3
View File
@@ -82,7 +82,7 @@ func TestScanSubdir(t *testing.T) {
// 2
log.Println("Creating a file in an unknown directory")
os.MkdirAll("s1/filetest", 0755)
os.MkdirAll("s1/filetest", 0o755)
if fd, err := os.Create("s1/filetest/file1.txt"); err != nil {
t.Fatal(err)
} else {
@@ -101,7 +101,7 @@ func TestScanSubdir(t *testing.T) {
// 3
log.Println("Creating a file in an unknown deep directory")
os.MkdirAll("s1/filetest/1/2/3/4/5/6/7", 0755)
os.MkdirAll("s1/filetest/1/2/3/4/5/6/7", 0o755)
if fd, err := os.Create("s1/filetest/1/2/3/4/5/6/7/file1.txt"); err != nil {
t.Fatal(err)
} else {
@@ -120,7 +120,7 @@ func TestScanSubdir(t *testing.T) {
// 4
log.Println("Creating a directory in an unknown directory")
err = os.MkdirAll("s1/dirtest/1/2/3/4/5/6/7", 0755)
err = os.MkdirAll("s1/dirtest/1/2/3/4/5/6/7", 0o755)
if err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -102,7 +102,7 @@ func testSymlinks(t *testing.T) {
// A directory that we will replace with a symlink later
err = os.Mkdir("s1/dirToReplace", 0755)
err = os.Mkdir("s1/dirToReplace", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -121,7 +121,7 @@ func testSymlinks(t *testing.T) {
// A directory and a symlink to that directory
err = os.Mkdir("s1/dir", 0755)
err = os.Mkdir("s1/dir", 0o755)
if err != nil {
t.Fatal(err)
}
@@ -218,7 +218,7 @@ func testSymlinks(t *testing.T) {
log.Fatal(err)
}
err = os.Mkdir("s1/repDirLink", 0755)
err = os.Mkdir("s1/repDirLink", 0o755)
if err != nil {
log.Fatal(err)
}
+2 -2
View File
@@ -203,7 +203,7 @@ func TestSyncCluster(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fd, err := os.OpenFile("s1/test-appendfile", os.O_APPEND|os.O_WRONLY, 0644)
fd, err := os.OpenFile("s1/test-appendfile", os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
t.Fatal(err)
}
@@ -326,7 +326,7 @@ func TestSyncSparseFile(t *testing.T) {
log.Println("Generating files...")
if err := os.Mkdir("s1", 0755); err != nil {
if err := os.Mkdir("s1", 0o755); err != nil {
t.Fatal(err)
}
+6 -1
View File
@@ -26,18 +26,23 @@ func TestBenchmarkTransferManyFiles(t *testing.T) {
func TestBenchmarkTransferLargeFile1G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 30)
}
func TestBenchmarkTransferLargeFile2G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 31)
}
func TestBenchmarkTransferLargeFile4G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 32)
}
func TestBenchmarkTransferLargeFile8G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 33)
}
func TestBenchmarkTransferLargeFile16G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 34)
}
func TestBenchmarkTransferLargeFile32G(t *testing.T) {
setupAndBenchmarkTransfer(t, 1, 35)
}
@@ -54,7 +59,7 @@ func setupAndBenchmarkTransfer(t *testing.T, files, sizeExp int) {
if err != nil {
t.Fatal(err)
}
err = os.MkdirAll("s1", 0755)
err = os.MkdirAll("s1", 0o755)
if err != nil {
t.Fatal(err)
}
+7 -7
View File
@@ -60,7 +60,7 @@ func generateFilesWithTime(dir string, files, maxexp int, srcname string, t0 tim
}
p0 := filepath.Join(dir, string(n[0]), n[0:2])
err = os.MkdirAll(p0, 0755)
err = os.MkdirAll(p0, 0o755)
if err != nil {
log.Fatal(err)
}
@@ -99,7 +99,7 @@ func generateOneFile(fd io.ReadSeeker, p1 string, s int64, t0 time.Time) error {
return err
}
os.Chmod(p1, os.FileMode(rand.Intn(0777)|0400))
os.Chmod(p1, os.FileMode(rand.Intn(0o777)|0o400))
t := t0.Add(-time.Duration(rand.Intn(30*86400)) * time.Second)
err = os.Chtimes(p1, t, t)
@@ -149,15 +149,15 @@ func alterFiles(dir string) error {
return removeAll(path)
case r == 1 && info.Mode().IsRegular():
if info.Mode()&0200 != 0200 {
if info.Mode()&0o200 != 0o200 {
// Not owner writable. Fix.
if err = os.Chmod(path, 0644); err != nil {
if err = os.Chmod(path, 0o644); err != nil {
return err
}
}
// Overwrite a random kilobyte of every tenth file
fd, err := os.OpenFile(path, os.O_RDWR, 0644)
fd, err := os.OpenFile(path, os.O_RDWR, 0o644)
if err != nil {
return err
}
@@ -291,8 +291,8 @@ func removeAll(dirs ...string) error {
if err != nil {
return err
}
if info.Mode()&0700 != 0700 {
os.Chmod(path, 0777)
if info.Mode()&0o700 != 0o700 {
os.Chmod(path, 0o777)
}
return nil
})