Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use path and filepath operation appropriately. #1406

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cloudflared/service_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"text/template"

homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error {
fileMode = st.FileMode
}

plistFolder := path.Dir(resolvedPath)
plistFolder := filepath.Dir(resolvedPath)
err = os.MkdirAll(plistFolder, 0o755)
if err != nil {
return fmt.Errorf("error creating %s: %v", plistFolder, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloudflared/tunnel/subcommand_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (sc *subcommandContext) readTunnelCredentials(credFinder CredFinder) (conne

var credentials connection.Credentials
if err = json.Unmarshal(body, &credentials); err != nil {
if strings.HasSuffix(filePath, ".pem") {
if filepath.Ext(filePath) == ".pem" {
return connection.Credentials{}, fmt.Errorf("The tunnel credentials file should be .json but you gave a .pem. " +
"The tunnel credentials file was originally created by `cloudflared tunnel create`. " +
"You may have accidentally used the filepath to cert.pem, which is generated by `cloudflared tunnel " +
Expand Down
6 changes: 3 additions & 3 deletions cmd/cloudflared/updater/workers_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"text/template"
"time"

Expand Down Expand Up @@ -198,15 +198,15 @@ func download(url, filepath string, isCompressed bool) error {

// isCompressedFile is a really simple file extension check to see if this is a macos tar and gzipped
func isCompressedFile(urlstring string) bool {
if strings.HasSuffix(urlstring, ".tgz") {
if path.Ext(urlstring) == ".tgz" {
return true
}

u, err := url.Parse(urlstring)
if err != nil {
return false
}
return strings.HasSuffix(u.Path, ".tgz")
return path.Ext(u.Path) == ".tgz"
}

// writeBatchFile writes a batch file out to disk
Expand Down
4 changes: 2 additions & 2 deletions credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package credentials
import (
"io/fs"
"os"
"path"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -13,7 +13,7 @@ func TestCredentialsRead(t *testing.T) {
file, err := os.ReadFile("test-cloudflare-tunnel-cert-json.pem")
require.NoError(t, err)
dir := t.TempDir()
certPath := path.Join(dir, originCertFile)
certPath := filepath.Join(dir, originCertFile)
os.WriteFile(certPath, file, fs.ModePerm)
user, err := Read(certPath, &nopLog)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions credentials/origin_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"testing"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestFindOriginCert_Valid(t *testing.T) {
file, err := os.ReadFile("test-cloudflare-tunnel-cert-json.pem")
require.NoError(t, err)
dir := t.TempDir()
certPath := path.Join(dir, originCertFile)
certPath := filepath.Join(dir, originCertFile)
os.WriteFile(certPath, file, fs.ModePerm)
path, err := FindOriginCert(certPath, &nopLog)
require.NoError(t, err)
Expand All @@ -104,7 +104,7 @@ func TestFindOriginCert_Valid(t *testing.T) {

func TestFindOriginCert_Missing(t *testing.T) {
dir := t.TempDir()
certPath := path.Join(dir, originCertFile)
certPath := filepath.Join(dir, originCertFile)
_, err := FindOriginCert(certPath, &nopLog)
require.Error(t, err)
}
3 changes: 1 addition & 2 deletions logger/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"sync"
"time"
Expand Down Expand Up @@ -257,7 +256,7 @@ func createRollingLogger(config RollingConfig) (io.Writer, error) {
}

rotatingFileInit.writer = &lumberjack.Logger{
Filename: path.Join(config.Dirname, config.Filename),
Filename: filepath.Join(config.Dirname, config.Filename),
MaxBackups: config.maxBackups,
MaxSize: config.maxSize,
MaxAge: config.maxAge,
Expand Down