-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix file retention after updates on macOS #417
This fixes issue #417 where autoupdate installer files were not deleted on macOS, leading to accumulation of old installers. Key changes: - Store update files in application-specific directory - Clear update files directory on every app launch Other supporting changes: - Refactor file system operations to be more testable and reusable - Improve separation of concerns in directory management - Enhance dependency injection for auto-update logic - Fix async completion to support `await` operations - Add additional logging and revise some log messages during updates
- Loading branch information
1 parent
4e06d54
commit ad35f8a
Showing
44 changed files
with
1,482 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/infrastructure/CodeRunner/Creation/Directory/ScriptDirectoryProvider.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 7 additions & 51 deletions
58
src/infrastructure/CodeRunner/System/NodeElectronSystemOperations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,13 @@ | ||
import { join } from 'node:path'; | ||
import { chmod, mkdir } from 'node:fs/promises'; | ||
import { exec } from 'node:child_process'; | ||
import { app } from 'electron/main'; | ||
import type { | ||
CommandOps, FileSystemOps, LocationOps, OperatingSystemOps, SystemOperations, | ||
} from './SystemOperations'; | ||
import { NodeElectronFileSystemOperations } from '@/infrastructure/FileSystem/NodeElectronFileSystemOperations'; | ||
import type { SystemOperations } from './SystemOperations'; | ||
|
||
/** | ||
* Thin wrapper for Node and Electron APIs. | ||
*/ | ||
export class NodeElectronSystemOperations implements SystemOperations { | ||
public readonly operatingSystem: OperatingSystemOps = { | ||
/* | ||
This method returns the directory for storing app's configuration files. | ||
It appends your app's name to the default appData directory. | ||
Conventionally, you should store user data files in this directory. | ||
However, avoid writing large files here as some environments might back up this directory | ||
to cloud storage, potentially causing issues with file size. | ||
Based on tests it returns: | ||
- Windows: `%APPDATA%\privacy.sexy` | ||
- Linux: `$HOME/.config/privacy.sexy/runs` | ||
- macOS: `$HOME/Library/Application Support/privacy.sexy/runs` | ||
For more details, refer to the Electron documentation: https://web.archive.org/web/20240104154857/https://www.electronjs.org/docs/latest/api/app#appgetpathname | ||
*/ | ||
getUserDataDirectory: () => { | ||
return app.getPath('userData'); | ||
}, | ||
}; | ||
|
||
public readonly location: LocationOps = { | ||
combinePaths: (...pathSegments) => join(...pathSegments), | ||
}; | ||
|
||
public readonly fileSystem: FileSystemOps = { | ||
setFilePermissions: ( | ||
filePath: string, | ||
mode: string | number, | ||
) => chmod(filePath, mode), | ||
createDirectory: async ( | ||
directoryPath: string, | ||
isRecursive?: boolean, | ||
) => { | ||
await mkdir(directoryPath, { recursive: isRecursive }); | ||
// Ignoring the return value from `mkdir`, which is the first directory created | ||
// when `recursive` is true, or empty return value. | ||
// See https://github.com/nodejs/node/pull/31530 | ||
}, | ||
}; | ||
|
||
public readonly command: CommandOps = { | ||
export const NodeElectronSystemOperations: SystemOperations = { | ||
fileSystem: NodeElectronFileSystemOperations, | ||
command: { | ||
exec, | ||
}; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
import type { FileSystemOperations } from '@/infrastructure/FileSystem/FileSystemOperations'; | ||
import type { exec } from 'node:child_process'; | ||
|
||
export interface SystemOperations { | ||
readonly operatingSystem: OperatingSystemOps; | ||
readonly location: LocationOps; | ||
readonly fileSystem: FileSystemOps; | ||
readonly fileSystem: FileSystemOperations; | ||
readonly command: CommandOps; | ||
} | ||
|
||
export interface OperatingSystemOps { | ||
getUserDataDirectory(): string; | ||
} | ||
|
||
export interface LocationOps { | ||
combinePaths(...pathSegments: string[]): string; | ||
} | ||
|
||
export interface CommandOps { | ||
exec(command: string): ReturnType<typeof exec>; | ||
} | ||
|
||
export interface FileSystemOps { | ||
setFilePermissions(filePath: string, mode: string | number): Promise<void>; | ||
createDirectory(directoryPath: string, isRecursive?: boolean): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/infrastructure/FileSystem/Directory/ApplicationDirectoryProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export interface ApplicationDirectoryProvider { | ||
provideDirectory(type: DirectoryType): Promise<DirectoryCreationOutcome>; | ||
} | ||
|
||
export type DirectoryType = 'update-installation-files' | 'script-runs'; | ||
|
||
export type DirectoryCreationOutcome = SuccessfulDirectoryCreation | FailedDirectoryCreation; | ||
|
||
export type DirectoryCreationErrorType = 'PathConstructionError' | 'DirectoryWriteError' | 'UserDataFolderRetrievalError'; | ||
|
||
export interface DirectoryCreationError { | ||
readonly type: DirectoryCreationErrorType; | ||
readonly message: string; | ||
} | ||
|
||
interface DirectoryCreationStatus { | ||
readonly success: boolean; | ||
readonly directoryAbsolutePath?: string; | ||
readonly error?: DirectoryCreationError; | ||
} | ||
|
||
interface SuccessfulDirectoryCreation extends DirectoryCreationStatus { | ||
readonly success: true; | ||
readonly directoryAbsolutePath: string; | ||
} | ||
|
||
interface FailedDirectoryCreation extends DirectoryCreationStatus { | ||
readonly success: false; | ||
readonly error: DirectoryCreationError; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface FileSystemOperations { | ||
getUserDataDirectory(): string; | ||
|
||
setFilePermissions(filePath: string, mode: string | number): Promise<void>; | ||
createDirectory(directoryPath: string, isRecursive?: boolean): Promise<void>; | ||
|
||
isFileAvailable(filePath: string): Promise<boolean>; | ||
isDirectoryAvailable(filePath: string): Promise<boolean>; | ||
deletePath(filePath: string): Promise<void>; | ||
listDirectoryContents(directoryPath: string): Promise<string[]>; | ||
|
||
combinePaths(...pathSegments: string[]): string; | ||
|
||
readFile: (filePath: string, encoding: NodeJS.BufferEncoding) => Promise<string>; | ||
writeFile: ( | ||
filePath: string, | ||
fileContents: string, | ||
encoding: NodeJS.BufferEncoding, | ||
) => Promise<void>; | ||
} |
Oops, something went wrong.