1919import com .nextcloud .client .device .PowerManagementService ;
2020import com .nextcloud .client .jobs .BackgroundJobManager ;
2121import com .nextcloud .client .jobs .ContentObserverWork ;
22+ import com .nextcloud .client .jobs .autoUpload .AutoUploadHelper ;
2223import com .nextcloud .client .jobs .upload .FileUploadHelper ;
23- import com .nextcloud .client .jobs .upload .FileUploadWorker ;
2424import com .nextcloud .client .network .ConnectivityService ;
2525import com .nextcloud .utils .extensions .UriExtensionsKt ;
2626import com .owncloud .android .MainApp ;
3131import com .owncloud .android .datamodel .UploadsStorageManager ;
3232import com .owncloud .android .lib .common .utils .Log_OC ;
3333
34- import org .lukhnos .nnio .file .AccessDeniedException ;
35- import org .lukhnos .nnio .file .FileVisitResult ;
36- import org .lukhnos .nnio .file .FileVisitor ;
37- import org .lukhnos .nnio .file .Files ;
38- import org .lukhnos .nnio .file .Path ;
39- import org .lukhnos .nnio .file .Paths ;
40- import org .lukhnos .nnio .file .SimpleFileVisitor ;
41- import org .lukhnos .nnio .file .attribute .BasicFileAttributes ;
42- import org .lukhnos .nnio .file .impl .FileBasedPathImpl ;
43-
4434import java .io .File ;
45- import java .io .IOException ;
46- import java .util .Arrays ;
47- import java .util .Collections ;
4835
4936import static com .owncloud .android .datamodel .OCFile .PATH_SEPARATOR ;
5037
@@ -60,110 +47,7 @@ private FilesSyncHelper() {
6047 // utility class -> private constructor
6148 }
6249
63- /**
64- * Copy of {@link Files#walkFileTree(Path, FileVisitor)} that walks the file tree in random order.
65- *
66- * @see org.lukhnos.nnio.file.Files#walkFileTree(Path, FileVisitor)
67- */
68- public static void walkFileTreeRandomly (Path start , FileVisitor <? super Path > visitor ) throws IOException {
69- File file = start .toFile ();
70- if (!file .canRead ()) {
71- Log_OC .d (TAG , "walkFileTreeRandomly, cant read the file: " + file .getAbsolutePath ());
72- visitor .visitFileFailed (start , new AccessDeniedException (file .toString ()));
73- } else {
74- Log_OC .d (TAG , "walkFileTreeRandomly, reading file: " + file .getAbsolutePath ());
75-
76- if (Files .isDirectory (start )) {
77- Log_OC .d (TAG , "walkFileTreeRandomly, file is directory: " + file .getAbsolutePath ());
78-
79- FileVisitResult preVisitDirectoryResult = visitor .preVisitDirectory (start , null );
80- if (preVisitDirectoryResult == FileVisitResult .CONTINUE ) {
81- Log_OC .d (TAG , "walkFileTreeRandomly, preVisitDirectoryResult == FileVisitResult.CONTINUE" );
82- File [] children = start .toFile ().listFiles ();
83- if (children != null ) {
84- Log_OC .d (TAG , "walkFileTreeRandomly, children exists" );
85-
86- Collections .shuffle (Arrays .asList (children ));
87- File [] var5 = children ;
88- int var6 = children .length ;
89-
90- for (int var7 = 0 ; var7 < var6 ; ++var7 ) {
91- Log_OC .d (TAG , "walkFileTreeRandomly -- recursive call" );
92- File child = var5 [var7 ];
93- walkFileTreeRandomly (FileBasedPathImpl .get (child ), visitor );
94- }
95-
96- visitor .postVisitDirectory (start , null );
97- } else {
98- Log_OC .w (TAG , "walkFileTreeRandomly, children is null" );
99- }
100- } else {
101- Log_OC .w (TAG , "walkFileTreeRandomly, preVisitDirectoryResult != FileVisitResult.CONTINUE" );
102- }
103- } else {
104- Log_OC .d (TAG , "walkFileTreeRandomly, file is not directory" );
105- visitor .visitFile (start , new BasicFileAttributes (file ));
106- }
107- }
108- }
109-
110- private static void insertCustomFolderIntoDB (Path path ,
111- SyncedFolder syncedFolder ,
112- FilesystemDataProvider filesystemDataProvider ,
113- long lastCheck ) {
114- Log_OC .d (TAG , "insertCustomFolderIntoDB called" );
115- final long enabledTimestampMs = syncedFolder .getEnabledTimestampMs ();
116-
117- try {
118- walkFileTreeRandomly (path , new SimpleFileVisitor <>() {
119- @ Override
120- public FileVisitResult visitFile (Path path , BasicFileAttributes attrs ) {
121- File file = path .toFile ();
122- if (syncedFolder .isExcludeHidden () && file .isHidden ()) {
123- Log_OC .w (TAG , "skipping files, exclude hidden file/folder: " + path );
124- // exclude hidden file or folder
125- return FileVisitResult .CONTINUE ;
126- }
127-
128- if (attrs .lastModifiedTime ().toMillis () < lastCheck ) {
129- Log_OC .w (TAG , "skipping files that already checked: " + path );
130- // skip files that were already checked
131- return FileVisitResult .CONTINUE ;
132- }
133-
134- if (syncedFolder .isExisting () || attrs .lastModifiedTime ().toMillis () >= enabledTimestampMs ) {
135- // storeOrUpdateFileValue takes a few ms
136- // -> Rest of this file check takes not even 1 ms.
137- filesystemDataProvider .storeOrUpdateFileValue (path .toAbsolutePath ().toString (),
138- attrs .lastModifiedTime ().toMillis (),
139- file .isDirectory (), syncedFolder );
140- } else {
141- Log_OC .w (TAG , "skipping files. SynchedFolder not exists or enabledTimestampMs not meeting condition" + path );
142- }
143-
144- return FileVisitResult .CONTINUE ;
145- }
146-
147- @ Override
148- public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) {
149- if (syncedFolder .isExcludeHidden () && dir .compareTo (Paths .get (syncedFolder .getLocalPath ())) != 0 && dir .toFile ().isHidden ()) {
150- Log_OC .d (TAG , "skipping hidden path: " + dir .getFileName ());
151- return FileVisitResult .SKIP_SUBTREE ;
152- }
153- return FileVisitResult .CONTINUE ;
154- }
155-
156- @ Override
157- public FileVisitResult visitFileFailed (Path file , IOException exc ) {
158- return FileVisitResult .CONTINUE ;
159- }
160- });
161- } catch (IOException e ) {
162- Log_OC .e (TAG , "Something went wrong while indexing files for auto upload: " + e .getLocalizedMessage ());
163- }
164- }
165-
166- public static void insertAllDBEntriesForSyncedFolder (SyncedFolder syncedFolder ) {
50+ public static void insertAllDBEntriesForSyncedFolder (SyncedFolder syncedFolder , AutoUploadHelper helper ) {
16751 Log_OC .d (TAG , "insertAllDBEntriesForSyncedFolder, called. ID: " + syncedFolder .getId ());
16852
16953 final Context context = MainApp .getAppContext ();
@@ -197,8 +81,7 @@ public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder)
19781 } else {
19882 Log_OC .d (TAG , "inserting other media types: " + mediaType .toString ());
19983 FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider (contentResolver );
200- Path path = Paths .get (syncedFolder .getLocalPath ());
201- FilesSyncHelper .insertCustomFolderIntoDB (path , syncedFolder , filesystemDataProvider , lastCheckTimestampMs );
84+ helper .insertCustomFolderIntoDB (syncedFolder , filesystemDataProvider );
20285 }
20386
20487 Log_OC .d (TAG ,"File-sync finished full check for custom folder " +syncedFolder .getLocalPath ()+" within " +(System .nanoTime () - startTime )+ "ns" );
0 commit comments