v0.2.3: fix export write failures and Ctrl+C cancellation
- Add ensure_directory calls in both export functions (preview + original) - Include NSError.localizedDescription in write failed messages - Make semaphore_wait_with_timeout poll photos_cancelled every ~1s - Add status messages: auth, loading tree, per-album progress - Fix parallel export: slot-based progress shows results in order
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
BINARY := ./bin/photoscli
|
BINARY := ./bin/photoscli
|
||||||
MODULE := gitea.k3s.k0.nu/tools/photocli
|
MODULE := gitea.k3s.k0.nu/tools/photocli
|
||||||
VERSION := 0.2.1
|
VERSION := 0.2.3
|
||||||
BRIDGE_DIR := bridge
|
BRIDGE_DIR := bridge
|
||||||
LDFLAGS := -X main.version=$(VERSION)
|
LDFLAGS := -X main.version=$(VERSION)
|
||||||
OBJ := $(BRIDGE_DIR)/photokit_bridge.o
|
OBJ := $(BRIDGE_DIR)/photokit_bridge.o
|
||||||
|
|||||||
@@ -274,6 +274,10 @@ char *photos_export_preview_json(const char *asset_id, const char *output_dir, i
|
|||||||
NSString *nsOutputDir = [NSString stringWithUTF8String:output_dir];
|
NSString *nsOutputDir = [NSString stringWithUTF8String:output_dir];
|
||||||
if (!nsAssetId || !nsOutputDir) return json_from_object(make_error_dict(@"invalid UTF-8 in arguments"));
|
if (!nsAssetId || !nsOutputDir) return json_from_object(make_error_dict(@"invalid UTF-8 in arguments"));
|
||||||
|
|
||||||
|
if (!ensure_directory(nsOutputDir)) {
|
||||||
|
return json_from_object(make_error_dict(@"failed to create output directory"));
|
||||||
|
}
|
||||||
|
|
||||||
PHFetchResult<PHAsset *> *fetch = [PHAsset fetchAssetsWithLocalIdentifiers:@[nsAssetId] options:nil];
|
PHFetchResult<PHAsset *> *fetch = [PHAsset fetchAssetsWithLocalIdentifiers:@[nsAssetId] options:nil];
|
||||||
if (fetch.count == 0) return json_from_object(make_error_dict(@"asset not found"));
|
if (fetch.count == 0) return json_from_object(make_error_dict(@"asset not found"));
|
||||||
|
|
||||||
@@ -322,7 +326,8 @@ char *photos_export_preview_json(const char *asset_id, const char *output_dir, i
|
|||||||
|
|
||||||
NSError *writeErr = nil;
|
NSError *writeErr = nil;
|
||||||
if (![imageData writeToFile:filepath options:NSDataWritingAtomic error:&writeErr]) {
|
if (![imageData writeToFile:filepath options:NSDataWritingAtomic error:&writeErr]) {
|
||||||
return json_from_object(@{@"error": @"write failed", @"cloud": asset_cloud_status_string(asset)});
|
NSString *msg = writeErr ? writeErr.localizedDescription : @"unknown write error";
|
||||||
|
return json_from_object(@{@"error": [NSString stringWithFormat:@"write failed: %@", msg], @"cloud": asset_cloud_status_string(asset)});
|
||||||
}
|
}
|
||||||
|
|
||||||
NSNumber *fileSize = nil;
|
NSNumber *fileSize = nil;
|
||||||
@@ -345,6 +350,10 @@ char *photos_export_original_json(const char *asset_id, const char *output_dir,
|
|||||||
NSString *nsOutputDir = [NSString stringWithUTF8String:output_dir];
|
NSString *nsOutputDir = [NSString stringWithUTF8String:output_dir];
|
||||||
if (!nsAssetId || !nsOutputDir) return json_from_object(make_error_dict(@"invalid UTF-8 in arguments"));
|
if (!nsAssetId || !nsOutputDir) return json_from_object(make_error_dict(@"invalid UTF-8 in arguments"));
|
||||||
|
|
||||||
|
if (!ensure_directory(nsOutputDir)) {
|
||||||
|
return json_from_object(make_error_dict(@"failed to create output directory"));
|
||||||
|
}
|
||||||
|
|
||||||
PHFetchResult<PHAsset *> *fetch = [PHAsset fetchAssetsWithLocalIdentifiers:@[nsAssetId] options:nil];
|
PHFetchResult<PHAsset *> *fetch = [PHAsset fetchAssetsWithLocalIdentifiers:@[nsAssetId] options:nil];
|
||||||
if (fetch.count == 0) return json_from_object(make_error_dict(@"asset not found"));
|
if (fetch.count == 0) return json_from_object(make_error_dict(@"asset not found"));
|
||||||
|
|
||||||
@@ -382,7 +391,7 @@ char *photos_export_original_json(const char *asset_id, const char *output_dir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (writeErr) {
|
if (writeErr) {
|
||||||
return json_from_object(@{@"error": @"write failed", @"cloud": asset_cloud_status_string(asset)});
|
return json_from_object(@{@"error": [NSString stringWithFormat:@"write failed: %@", writeErr.localizedDescription], @"cloud": asset_cloud_status_string(asset)});
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *writtenFilename = [filepath lastPathComponent];
|
NSString *writtenFilename = [filepath lastPathComponent];
|
||||||
|
|||||||
Reference in New Issue
Block a user