Add .incomplete to end of wip files

This commit is contained in:
Evan Su 2025-04-13 14:24:02 -04:00
parent 9e7e2e9c44
commit 16bb70dc97
2 changed files with 19 additions and 11 deletions

View file

@ -7,6 +7,7 @@
<ul> <ul>
<li>✓ Allow pressing 'Enter' key to press Start/Process button</li> <li>✓ Allow pressing 'Enter' key to press Start/Process button</li>
<li>✓ Encrypt previously unencrypted temporary zip files</li> <li>✓ Encrypt previously unencrypted temporary zip files</li>
<li>✓ Add `.incomplete` to filenames while work is in progress</li>
</ul> </ul>
# v1.47 (Released 02/19/2025) # v1.47 (Released 02/19/2025)

View file

@ -1115,7 +1115,7 @@ func work() {
} }
// Open a temporary .zip for writing // Open a temporary .zip for writing
inputFile = strings.TrimSuffix(outputFile, ".pcv") inputFile = strings.TrimSuffix(outputFile, ".pcv") + ".tmp"
file, err := os.Create(inputFile) file, err := os.Create(inputFile)
if err != nil { // Make sure file is writable if err != nil { // Make sure file is writable
accessDenied("Write") accessDenied("Write")
@ -1388,7 +1388,7 @@ func work() {
} }
// Create the output file // Create the output file
fout, err = os.Create(outputFile) fout, err = os.Create(outputFile + ".incomplete")
if err != nil { if err != nil {
fin.Close() fin.Close()
if len(allFiles) > 1 || len(onlyFolders) > 0 || compress { if len(allFiles) > 1 || len(onlyFolders) > 0 || compress {
@ -1473,7 +1473,7 @@ func work() {
if len(allFiles) > 1 || len(onlyFolders) > 0 || compress { if len(allFiles) > 1 || len(onlyFolders) > 0 || compress {
os.Remove(inputFile) os.Remove(inputFile)
} }
os.Remove(outputFile) os.Remove(fout.Name())
return return
} }
} }
@ -1705,7 +1705,7 @@ func work() {
} }
// Create the output file for decryption // Create the output file for decryption
fout, err = os.Create(outputFile) fout, err = os.Create(outputFile + ".incomplete")
if err != nil { if err != nil {
fin.Close() fin.Close()
if recombine { if recombine {
@ -1771,7 +1771,7 @@ func work() {
if recombine || len(allFiles) > 1 || len(onlyFolders) > 0 || compress { if recombine || len(allFiles) > 1 || len(onlyFolders) > 0 || compress {
os.Remove(inputFile) os.Remove(inputFile)
} }
os.Remove(outputFile) os.Remove(fout.Name())
return return
} }
@ -1908,7 +1908,7 @@ func work() {
if recombine || len(allFiles) > 1 || len(onlyFolders) > 0 || compress { if recombine || len(allFiles) > 1 || len(onlyFolders) > 0 || compress {
os.Remove(inputFile) os.Remove(inputFile)
} }
os.Remove(outputFile) os.Remove(fout.Name())
return return
} }
@ -1987,6 +1987,8 @@ func work() {
fin.Close() fin.Close()
fout.Close() fout.Close()
os.Rename(outputFile+".incomplete", outputFile)
// Add plausible deniability // Add plausible deniability
if mode == "encrypt" && deniability { if mode == "encrypt" && deniability {
popupStatus = "Adding plausible deniability..." popupStatus = "Adding plausible deniability..."
@ -1994,13 +1996,13 @@ func work() {
giu.Update() giu.Update()
// Get size of volume for showing progress // Get size of volume for showing progress
stat, _ := os.Stat(fout.Name()) stat, _ := os.Stat(outputFile)
total := stat.Size() total := stat.Size()
// Rename the output volume to free up the filename // Rename the output volume to free up the filename
os.Rename(fout.Name(), fout.Name()+".tmp") os.Rename(outputFile, outputFile+".tmp")
fin, _ := os.Open(fout.Name() + ".tmp") fin, _ := os.Open(outputFile + ".tmp")
fout, _ := os.Create(fout.Name()) fout, _ := os.Create(outputFile + ".incomplete")
// Use a random Argon2 salt and XChaCha20 nonce // Use a random Argon2 salt and XChaCha20 nonce
salt := make([]byte, 16) salt := make([]byte, 16)
@ -2050,6 +2052,7 @@ func work() {
fin.Close() fin.Close()
fout.Close() fout.Close()
os.Remove(fin.Name()) os.Remove(fin.Name())
os.Rename(outputFile+".incomplete", outputFile)
canCancel = true canCancel = true
giu.Update() giu.Update()
} }
@ -2094,7 +2097,7 @@ func work() {
startTime := time.Now() startTime := time.Now()
for i := 0; i < chunks; i++ { for i := 0; i < chunks; i++ {
// Make the chunk // Make the chunk
fout, _ := os.Create(fmt.Sprintf("%s.%d", outputFile, i)) fout, _ := os.Create(fmt.Sprintf("%s.%d.incomplete", outputFile, i))
done := 0 done := 0
// Copy data into the chunk // Copy data into the chunk
@ -2160,6 +2163,10 @@ func work() {
fin.Close() fin.Close()
os.Remove(outputFile) os.Remove(outputFile)
names, _ = filepath.Glob(outputFile + ".*.incomplete")
for _, i := range names {
os.Rename(i, strings.TrimSuffix(i, ".incomplete"))
}
} }
canCancel = false canCancel = false