Skip to content

Commit 80a7a55

Browse files
david-allisoncriticalAY
authored andcommitted
refactor: extract 'Directory.kt' to common module
This allows us to break a circular dependency in `:compat` tests so they can be moved into the module Assisted by Claude Opus 4.6 - Plan by me, execution by Claude Issue 20547
1 parent 0498bdf commit 80a7a55

3 files changed

Lines changed: 37 additions & 18 deletions

File tree

AnkiDroid/src/test/java/com/ichi2/anki/model/DirectoryTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.ichi2.anki.model
1818

19+
import com.ichi2.anki.compat.hasFiles
1920
import com.ichi2.compat.Test21And26
2021
import com.ichi2.testutils.HamcrestUtils.containsInAnyOrder
2122
import com.ichi2.testutils.withTempFile

AnkiDroid/src/main/java/com/ichi2/anki/model/Directory.kt renamed to common/src/main/java/com/ichi2/anki/model/Directory.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
package com.ichi2.anki.model
1818

19-
import com.ichi2.anki.compat.CompatHelper
2019
import java.io.File
21-
import java.io.IOException
22-
import java.nio.file.NotDirectoryException
2320

2421
/**
2522
* A directory which is assumed to exist (existed when class was instantiated)
@@ -30,21 +27,6 @@ class Directory private constructor(
3027
/** List of files in this directory. If this is not a directory or no longer exists, then an empty array. */
3128
fun listFiles(): Array<out File> = directory.listFiles() ?: emptyArray()
3229

33-
/**
34-
* Whether this directory has at least files
35-
* @return Whether the directory has file.
36-
* @throws [SecurityException] If a security manager exists and its SecurityManager.checkRead(String)
37-
* method denies read access to the directory
38-
* @throws [java.io.FileNotFoundException] if the file do not exists
39-
* @throws [NotDirectoryException] if the file could not otherwise be opened because it is not
40-
* a directory (optional specific exception), (starting at API 26)
41-
* @throws [IOException] – if an I/O error occurs.
42-
* This also occurred on an existing directory because of permission issue
43-
* that we could not reproduce. See https://github.com/ankidroid/Anki-Android/issues/10358
44-
*/
45-
@Throws(IOException::class, SecurityException::class, NotDirectoryException::class)
46-
fun hasFiles(): Boolean = CompatHelper.compat.hasFiles(directory)
47-
4830
/** The [canonical path][java.io.File.getCanonicalPath] for the file */
4931
override fun toString(): String = directory.canonicalPath
5032

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2022 David Allison <davidallisongithub@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.anki.compat
18+
19+
import com.ichi2.anki.model.Directory
20+
import java.io.IOException
21+
import java.nio.file.NotDirectoryException
22+
23+
/**
24+
* Whether this directory has at least one file
25+
* @return Whether the directory has a file.
26+
* @throws [SecurityException] If a security manager exists and its SecurityManager.checkRead(String)
27+
* method denies read access to the directory
28+
* @throws [java.io.FileNotFoundException] if the file does not exist
29+
* @throws [NotDirectoryException] if the file could not otherwise be opened because it is not
30+
* a directory (optional specific exception), (starting at API 26)
31+
* @throws [IOException] if an I/O error occurs.
32+
* This also occurred on an existing directory because of permission issue
33+
* that we could not reproduce. See https://github.com/ankidroid/Anki-Android/issues/10358
34+
*/
35+
@Throws(IOException::class, SecurityException::class, NotDirectoryException::class)
36+
fun Directory.hasFiles(): Boolean = CompatHelper.compat.hasFiles(directory)

0 commit comments

Comments
 (0)