Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: rename in the same directory (#2672)
Yilong Lif945e4d8881c
diff --git a/plugin/db/mysql/restore.go b/plugin/db/mysql/restore.goindex 976b5e2da9..0d6250e8d3 100644--- a/plugin/db/mysql/restore.go+++ b/plugin/db/mysql/restore.go@@ -688,19 +688,18 @@ func (driver *Driver) getBinlogMetaFileListToDownload(ctx context.Context, clien// It may keep growing as there are ongoing writes to the database. So we just need to check that// the file size is larger or equal to the binlog file size we queried from the MySQL server earlier.func (driver *Driver) downloadBinlogFile(ctx context.Context, binlogFileToDownload BinlogFile, isLast bool) error {- tempDir := os.TempDir()- // for mysqlbinlog binary, --result-file must end with '/'- mysqlbinlogResultFileDir := strings.TrimRight(tempDir, "/") + "/"+ tempBinlogPrefix := filepath.Join(driver.binlogDir, "tmp-")// TODO(zp): support ssl?args := []string{binlogFileToDownload.Name,"--read-from-remote-server",// Verify checksum binlog events."--verify-binlog-checksum",- "--raw","--host", driver.connCfg.Host,"--user", driver.connCfg.Username,- "--result-file", mysqlbinlogResultFileDir,+ "--raw",+ // With --raw this is a prefix for the file names.+ "--result-file", tempBinlogPrefix,}if driver.connCfg.Port != "" {args = append(args, "--port", driver.connCfg.Port)@@ -714,7 +713,7 @@ func (driver *Driver) downloadBinlogFile(ctx context.Context, binlogFileToDownlocmd.Stderr = os.Stderrlog.Debug("Downloading binlog files using mysqlbinlog", zap.String("cmd", cmd.String()))- binlogFilePathTemp := filepath.Join(tempDir, binlogFileToDownload.Name)+ binlogFilePathTemp := tempBinlogPrefix + binlogFileToDownload.Namedefer os.Remove(binlogFilePathTemp)if err := cmd.Run(); err != nil {log.Error("Failed to execute mysqlbinlog binary", zap.Error(err))@@ -722,26 +721,26 @@ func (driver *Driver) downloadBinlogFile(ctx context.Context, binlogFileToDownlo}log.Debug("Checking downloaded binlog file stat", zap.String("path", binlogFilePathTemp))- binlogFileInfo, err := os.Stat(binlogFilePathTemp)+ binlogFileTempInfo, err := os.Stat(binlogFilePathTemp)if err != nil {log.Error("Failed to get stat of the binlog file.", zap.String("path", binlogFilePathTemp), zap.Error(err))return errors.Wrapf(err, "failed to get stat of the binlog file %q", binlogFilePathTemp)}- if !isLast && binlogFileInfo.Size() != binlogFileToDownload.Size {+ if !isLast && binlogFileTempInfo.Size() != binlogFileToDownload.Size {log.Error("Downloaded archived binlog file size is not equal to size queried on the MySQL server earlier.",zap.String("binlog", binlogFileToDownload.Name),zap.Int64("sizeInfo", binlogFileToDownload.Size),- zap.Int64("downloadedSize", binlogFileInfo.Size()),+ zap.Int64("downloadedSize", binlogFileTempInfo.Size()),)- return errors.Errorf("downloaded archived binlog file %q size %d is not equal to size %d queried on MySQL server earlier", binlogFilePathTemp, binlogFileInfo.Size(), binlogFileToDownload.Size)+ return errors.Errorf("downloaded archived binlog file %q size %d is not equal to size %d queried on MySQL server earlier", binlogFilePathTemp, binlogFileTempInfo.Size(), binlogFileToDownload.Size)}- binlogFilePath := filepath.Join(driver.binlogDir, binlogFileInfo.Name())+ binlogFilePath := filepath.Join(driver.binlogDir, binlogFileToDownload.Name)if err := os.Rename(binlogFilePathTemp, binlogFilePath); err != nil {return errors.Wrapf(err, "failed to rename %q to %q", binlogFilePathTemp, binlogFilePath)}- if err := driver.writeBinlogMetadataFile(ctx, binlogFileInfo.Name()); err != nil {+ if err := driver.writeBinlogMetadataFile(ctx, binlogFileToDownload.Name); err != nil {return errors.Wrapf(err, "failed to write binlog metadata file for binlog file %q", binlogFilePathTemp)}return nildiff --git a/plugin/storage/s3/s3.go b/plugin/storage/s3/s3.goindex f070c326ff..36125ee039 100644--- a/plugin/storage/s3/s3.go+++ b/plugin/storage/s3/s3.go@@ -5,7 +5,6 @@ import ("context""io""os"- "path/filepath""github.com/aws/aws-sdk-go-v2/aws"awsconfig "github.com/aws/aws-sdk-go-v2/config"@@ -104,9 +103,7 @@ func (c *Client) GetBucket() string {// In case of network errors which will get partially downloaded files, we first download to a temporary file.// After that, we then rename it to the target file path.func (c *Client) DownloadFileFromCloud(ctx context.Context, filePathLocal, filePathOnCloud string) error {- tempDir := os.TempDir()- baseName := filepath.Base(filePathLocal)- filePathTemp := filepath.Join(tempDir, baseName)+ filePathTemp := filePathLocal + ".tmp"fileTemp, err := os.Create(filePathTemp)if err != nil {return errors.Wrapf(err, "failed to create the local temporary file %s", filePathTemp)