Skip to content

Commit 59e972d

Browse files
authored
Merge pull request #1044 from nextcloud/fix/webdav-and-tests
test(dav): Add tests for dav interface to full-run-test.yml
2 parents 70c0c23 + 7d45a66 commit 59e972d

11 files changed

Lines changed: 79 additions & 28 deletions

File tree

‎.github/workflows/cluster-faces-test.yml‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717

1818
jobs:
1919
php:
20-
runs-on: ubuntu-latest
20+
runs-on: ubuntu-20.04
2121

2222
strategy:
2323
# do not stop on another job's failure
@@ -132,21 +132,36 @@ jobs:
132132
run: |
133133
./occ app:enable -vvv ${{ env.APP_NAME }}
134134
135+
- name: Remove unnecessary models to make space
136+
run: |
137+
rm -rf apps/recognize/models
138+
139+
- uses: actions/cache/restore@v3
140+
id: photos-cache
141+
with:
142+
path: data/admin/files/
143+
key: https://cloud.marcelklehr.de/s/PkNYbmKnwMiQMFD/download/IMDb-Face.zip
144+
135145
- name: Upload photos
146+
if: steps.photos-cache.outputs.cache-hit != 'true'
136147
run: |
137148
mkdir -p data/admin/files/
138149
cd data/admin/files
139150
wget https://cloud.marcelklehr.de/s/PkNYbmKnwMiQMFD/download/IMDb-Face.zip
140151
unzip IMDb-Face.zip
141152
rm IMDb-Face.zip
142153
143-
- name: Set pure-js mode
144-
run: |
145-
./occ config:app:set --value ${{ matrix.pure-js-mode }} recognize tensorflow.purejs
154+
- uses: actions/cache/save@v3
155+
with:
156+
path: data/admin/files/
157+
key: https://cloud.marcelklehr.de/s/PkNYbmKnwMiQMFD/download/IMDb-Face.zip
146158

147-
- name: Set faces.enabled
159+
- name: Set config
148160
run: |
161+
./occ config:app:set --value ${{ matrix.pure-js-mode }} recognize tensorflow.purejs
149162
./occ config:app:set --value true recognize faces.enabled
163+
# only use one core. GH actions has 2
164+
./occ config:app:set --value 1 recognize tensorflow.cores
150165
151166
- uses: actions/cache/restore@v3
152167
id: db-cache
@@ -183,7 +198,7 @@ jobs:
183198
id: clustering-cache
184199
with:
185200
path: out.json
186-
key: ${{ runner.os }}-${{ hashFiles('out.txt', 'apps/recognize/src/classifier_faces.js', 'apps/recognize/lib/Classifiers/Classifier.php', 'apps/recognize/lib/Classifiers/Images/ClusteringFaceClassifier.php', 'apps/recognize/lib/Clustering/**', 'apps/recognize/lib/Service/FaceClusterAnalyzer.php', 'apps/recognize/lib/Command/ClusterFaces.php') }}-${{ matrix.pure-js-mode }}
201+
key: ${{ runner.os }}-${{ hashFiles('out.txt', 'apps/recognize/src/classifier_faces.js', 'apps/recognize/lib/Classifiers/Classifier.php', 'apps/recognize/lib/Classifiers/Images/ClusteringFaceClassifier.php', 'apps/recognize/lib/Clustering/**', 'apps/recognize/lib/Dav/**', 'apps/recognize/lib/Service/FaceClusterAnalyzer.php', 'apps/recognize/lib/Command/ClusterFaces.php') }}-${{ matrix.pure-js-mode }}
187202

188203
- name: Run clustering
189204
if: steps.clustering-cache.outputs.cache-hit != 'true'

‎.github/workflows/full-run-test.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,28 @@ jobs:
181181
run: |
182182
./occ recognize:classify
183183
./occ recognize:cluster-faces
184+
185+
- name: Install cadaver
186+
if: ${{ matrix.faces-enabled }}
187+
run: |
188+
sudo apt -y install cadaver
189+
190+
- name: Test webdav access
191+
if: ${{ matrix.faces-enabled }}
192+
run: |
193+
cat > ~/.netrc <<EOF
194+
machine localhost
195+
login admin
196+
password password
197+
EOF
198+
cadaver http://localhost:8080/remote.php/dav/recognize/admin/ <<EOF
199+
mv unassigned-faces/* faces/0/
200+
mkdir faces/toot
201+
mv faces/0/* faces/toot/
202+
mv faces/toot/ faces/blah/
203+
EOF
204+
205+
- name: Print logs
206+
if: always()
207+
run: |
208+
cat data/nextcloud.log

‎lib/BackgroundJobs/ClusterFacesJob.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ClusterFacesJob extends QueuedJob {
1919
private FaceClusterAnalyzer $clusterAnalyzer;
2020
private IJobList $jobList;
2121
private LoggerInterface $logger;
22-
2322
public const BATCH_SIZE = 10000;
2423
private SettingsService $settingsService;
2524

‎lib/Classifiers/Classifier.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
231231
$i++;
232232
}
233233
}
234+
$proc->stop();
234235
$this->cleanUpTmpFiles();
235236
if ($i !== count($paths)) {
236237
$this->logger->warning('Classifier process output: '.$errOut);
@@ -340,8 +341,10 @@ public function generatePreviewWithProvider(File $file): string {
340341
$previewImage = imagecreatefromstring(file_get_contents($tmpname));
341342
$use_gd_quality = (int)$this->config->getSystemValue('recognize.preview.quality', '100');
342343
if (imagejpeg($previewImage, $tmpname, $use_gd_quality) === false) {
344+
imagedestroy($previewImage);
343345
throw new \OCA\Recognize\Exception\Exception('Could not copy preview file to temp folder');
344346
}
347+
imagedestroy($previewImage);
345348
}
346349

347350
return $tmpname;
@@ -379,8 +382,12 @@ public function generatePreviewWithGD(string $path): string {
379382

380383
$use_gd_quality = (int)$this->config->getSystemValue('recognize.preview.quality', '100');
381384
if (imagejpeg($previewImage, $tmpname, $use_gd_quality) === false) {
385+
imagedestroy($image);
386+
imagedestroy($previewImage);
382387
throw new \OCA\Recognize\Exception\Exception('Could not copy preview file to temp folder');
383388
}
389+
imagedestroy($image);
390+
imagedestroy($previewImage);
384391

385392
return $tmpname;
386393
}

‎lib/Classifiers/Images/ClusteringFaceClassifier.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ public function classify(array $queueFiles): void {
115115
$this->logger->error('Could not store face detection in database', ['exception' => $e]);
116116
continue;
117117
}
118-
$usersToCluster[] = $userId;
118+
$usersToCluster[$userId] = true;
119119
}
120120
$this->config->setAppValue('recognize', self::MODEL_NAME.'.status', 'true');
121121
$this->config->setAppValue('recognize', self::MODEL_NAME.'.lastFile', time());
122122
}
123123
}
124124

125-
$usersToCluster = array_unique($usersToCluster);
125+
$usersToCluster = array_keys($usersToCluster);
126126
foreach ($usersToCluster as $userId) {
127127
if (!$this->jobList->has(ClusterFacesJob::class, ['userId' => $userId])) {
128128
$this->logger->debug('scheduling ClusterFacesJob for user '.$userId);

‎lib/Command/Classify.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
141141
}
142142
}
143143
} while ($i > 0);
144+
\OC_Util::tearDownFS();
144145
}
145146
return 0;
146147
}

‎lib/Dav/Faces/PropFindPlugin.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public function propFind(PropFind $propFind, INode $node) {
5050
)
5151
);
5252
});
53+
$propFind->handle(self::FILE_NAME_PROPERTYNAME, fn () => $node->getFile()->getName());
54+
$propFind->handle(self::REALPATH_PROPERTYNAME, fn () => $node->getFile()->getPath());
5355
$propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn () => $node->getFile()->getId());
5456
$propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, fn () => $node->getETag());
55-
$propFind->handle(self::FILE_NAME_PROPERTYNAME, fn () => $node->getFile()->getName());
5657
$propFind->handle(TagsPlugin::FAVORITE_PROPERTYNAME, fn () => $node->isFavorite() ? 1 : 0);
5758
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($this->previewManager->isAvailable($node->getFile()->getFileInfo())));
5859
$propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () use ($node): string {

‎lib/Dav/Faces/UnassignedFacesHome.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function __construct(IUser $user, FaceDetectionMapper $faceDetectionMappe
3030
$this->faceDetectionMapper = $faceDetectionMapper;
3131
$this->rootFolder = $rootFolder;
3232
$this->tagManager = $tagManager;
33-
$this->metadataManager = $metadataManager;
3433
$this->previewManager = $previewManager;
3534
}
3635

@@ -82,7 +81,7 @@ public function getChild($name): FacePhoto {
8281
throw new NotFound();
8382
}
8483

85-
return new UnassignedFacePhoto($this->faceDetectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->metadataManager, $this->previewManager);
84+
return new UnassignedFacePhoto($this->faceDetectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager);
8685
}
8786

8887
public function childExists($name): bool {

‎lib/Dav/RecognizeHome.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function __construct(array $principalInfo, FaceClusterMapper $faceCluster
3434
$this->faceDetectionMapper = $faceDetectionMapper;
3535
$this->rootFolder = $rootFolder;
3636
$this->tagManager = $tagManager;
37-
$this->metadataManager = $metadataManager;
3837
$this->previewManager = $previewManager;
3938
}
4039

@@ -60,11 +59,11 @@ public function createDirectory($name) {
6059
}
6160

6261
private function getFacesHome() {
63-
return new FacesHome($this->faceClusterMapper, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->metadataManager, $this->previewManager);
62+
return new FacesHome($this->faceClusterMapper, $this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->previewManager);
6463
}
6564

6665
private function getUnassignedFacesHome() {
67-
return new UnassignedFacesHome($this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->metadataManager, $this->previewManager);
66+
return new UnassignedFacesHome($this->user, $this->faceDetectionMapper, $this->rootFolder, $this->tagManager, $this->previewManager);
6867
}
6968

7069
public function getChild($name) {

‎lib/Service/StorageService.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ public function getMounts(): \Generator {
6666
// Only crawl files, not cache or trashbin
6767
$qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger, $this->metadataManager);
6868
try {
69-
/** @var array|false $root */
70-
$root = $qb->selectFileCache()
69+
$res = $qb->selectFileCache()
7170
->andWhere($qb->expr()->eq('filecache.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
7271
->andWhere($qb->expr()->eq('filecache.path', $qb->createNamedParameter('files')))
73-
->executeQuery()->fetch();
72+
->executeQuery();
73+
/** @var array|false $root */
74+
$root = $res->fetch();
75+
$res->closeCursor();
7476
if ($root !== false) {
7577
$overrideRoot = intval($root['fileid']);
7678
}

0 commit comments

Comments
 (0)