Skip to content
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
27 changes: 27 additions & 0 deletions packages/capacitor-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const readFilePath = async () => {
* [`stat(...)`](#stat)
* [`rename(...)`](#rename)
* [`copy(...)`](#copy)
* [`excludeFromBackup(...)`](#excludefrombackup)
* [`downloadFile(...)`](#downloadfile)
* [`addListener('progress', ...)`](#addlistenerprogress-)
* [`removeAllListeners()`](#removealllisteners)
Expand Down Expand Up @@ -461,6 +462,23 @@ Copy a file or directory
--------------------


### excludeFromBackup(...)

```typescript
excludeFromBackup(options: ExcludeFromBackupOptions) => Promise<void>
```

Exclude a file or directory from backup (iOS only).

| Param | Type |
| ------------- | ----------------------------------------------------------------------------- |
| **`options`** | <code><a href="#excludefrombackupoptions">ExcludeFromBackupOptions</a></code> |

**Since:** 7.2.0

--------------------


### downloadFile(...)

```typescript
Expand Down Expand Up @@ -676,6 +694,15 @@ We recommend using the @capacitor/file-transfer plugin instead, in conjunction w
| **`uri`** | <code>string</code> | The uri where the file was copied into | 4.0.0 |


#### ExcludeFromBackupOptions

| Prop | Type | Description | Default | Since |
| --------------- | ----------------------------------------------- | ------------------------------------------------------------------------------ | ------------------ | ----- |
| **`path`** | <code>string</code> | The path of the file or directory to exclude from backup | | 7.2.0 |
| **`directory`** | <code><a href="#directory">Directory</a></code> | The <a href="#directory">`Directory`</a> to exclude the file or directory from | | 7.2.0 |
| **`excluded`** | <code>boolean</code> | Whether to exclude the file or directory from backup | <code>false</code> | 7.2.0 |


#### DownloadFileResult

| Prop | Type | Description | Since |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Constants {
static let data = "data"
static let directory = "directory"
static let encoding = "encoding"
static let excluded = "excluded"
static let chunkSize = "chunkSize"
static let from = "from"
static let path = "path"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum IONFileMethod: String {
case getUri
case rename
case copy
case excludeFromBackup
}

enum FilesystemError: Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ enum FilesystemOperation {
case delete(url: URL)
case rename(source: URL, destination: URL)
case copy(source: URL, destination: URL)
case excludeFromBackup(url: URL, excluded: Bool)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class FilesystemOperationExecutor {
case .copy(let source, let destination):
try service.copyItem(fromURL: source, toURL: destination)
resultData = [Constants.ResultDataKey.uri: destination.absoluteString]
case .excludeFromBackup(var url, let excluded):
var values = URLResourceValues()
values.isExcludedFromBackup = excluded
try url.setResourceValues(values)
}

call.handleSuccess(resultData)
Expand Down Expand Up @@ -94,6 +98,7 @@ private extension FilesystemOperationExecutor {
case .getUri(let url): return FilesystemError.invalidPath(url.absoluteString)
case .rename(let sourceUrl, _): path = sourceUrl.absoluteString; method = .rename
case .copy(let sourceUrl, _): path = sourceUrl.absoluteString; method = .copy
case .excludeFromBackup(let url, _): path = url.absoluteString; method = .excludeFromBackup
}

return mapError(error, withPath: path, andMethod: method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class FilesystemPlugin: CAPPlugin, CAPBridgedPlugin {
CAPPluginMethod(name: "stat", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "rename", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "copy", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "excludeFromBackup", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "checkPermissions", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "requestPermissions", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "downloadFile", returnType: CAPPluginReturnPromise)
Expand Down Expand Up @@ -172,6 +173,16 @@ private extension FilesystemPlugin {
}
}

/**
* Excludes a file or directory from backup.
*/
@objc func excludeFromBackup(_ call: CAPPluginCall) {
let excluded = call.getBool(Constants.MethodParameter.excluded, false)
performSinglePathOperation(call) {
.excludeFromBackup(url: $0, excluded: excluded)
}
}

/**
* [DEPRECATED] Download a file
*/
Expand Down
31 changes: 31 additions & 0 deletions packages/capacitor-plugin/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,30 @@ export interface CopyOptions {

export type RenameOptions = CopyOptions;

export interface ExcludeFromBackupOptions {
/**
* The path of the file or directory to exclude from backup
*
* @since 7.2.0
*/
path: string;

/**
* The `Directory` to exclude the file or directory from
*
* @since 7.2.0
*/
directory?: Directory;

/**
* Whether to exclude the file or directory from backup
*
* @default false
* @since 7.2.0
*/
excluded: boolean;
}

export interface ReadFileResult {
/**
* The representation of the data contained in the file
Expand Down Expand Up @@ -668,6 +692,13 @@ export interface FilesystemPlugin {
*/
copy(options: CopyOptions): Promise<CopyResult>;

/**
* Exclude a file or directory from backup (iOS only).
*
* @since 7.2.0
*/
excludeFromBackup(options: ExcludeFromBackupOptions): Promise<void>;

/**
* Perform a http request to a server and download the file to the specified destination.
*
Expand Down
10 changes: 10 additions & 0 deletions packages/capacitor-plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
DownloadFileResult,
ProgressStatus,
ReadFileInChunksCallback,
ExcludeFromBackupOptions,
} from './definitions';
import { Encoding } from './definitions';

Expand Down Expand Up @@ -438,6 +439,15 @@ export class FilesystemWeb extends WebPlugin implements FilesystemPlugin {
return this._copy(options, false);
}

/**
* Exclude a file or directory from backup (iOS only).
* @param options the options for the exclude operation
* @return a promise that resolves with the exclude result
*/
async excludeFromBackup(_: ExcludeFromBackupOptions): Promise<void> {
throw this.unavailable('Method not implemented.');
}

async requestPermissions(): Promise<PermissionStatus> {
return { publicStorage: 'granted' };
}
Expand Down