@@ -24,16 +24,30 @@ class Adapter implements FilesystemAdapter
24
24
{
25
25
protected $ options = [];
26
26
27
+ protected const CONFLICT_BEHAVIOR_FAIL = 'fail ' ;
28
+ protected const CONFLICT_BEHAVIOR_IGNORE = 'ignore ' ;
29
+ protected const CONFLICT_BEHAVIOR_RENAME = 'rename ' ;
30
+ protected const CONFLICT_BEHAVIOR_REPLACE = 'replace ' ;
31
+
27
32
public function __construct (public Graph $ graph , protected string $ drive_id , array $ options = [])
28
33
{
29
34
$ default_options = [
30
35
'request_timeout ' => 90 , //Increase this for larger chunks / higher latency
31
36
'chunk_size ' => 320 * 1024 * 10 , //Microsoft requires chunks to be multiples of 320KB
32
- 'directory_conflict_behavior ' => ' fail ' , //rename, replace, fail
37
+ 'directory_conflict_behavior ' => static :: CONFLICT_BEHAVIOR_IGNORE , //ignore, rename, replace, fail
33
38
];
34
39
35
40
$ this ->options = array_merge ($ default_options , $ options );
36
-
41
+ switch ($ this ->options ['directory_conflict_behavior ' ]) {
42
+ case static ::CONFLICT_BEHAVIOR_FAIL :
43
+ case static ::CONFLICT_BEHAVIOR_IGNORE :
44
+ case static ::CONFLICT_BEHAVIOR_RENAME :
45
+ case static ::CONFLICT_BEHAVIOR_REPLACE :
46
+ break ;
47
+ default :
48
+ throw new Exception ('Invalid directory_conflict_behavior ' );
49
+ }
50
+
37
51
if ($ this ->options ['chunk_size ' ] % (320 * 1024 )) {
38
52
throw new Exception ('Chunk size must be a multiple of 320KB ' );
39
53
}
@@ -276,6 +290,10 @@ public function getChildrenUrl(string $path): string
276
290
277
291
public function createDirectory (string $ path , Config $ config ): void
278
292
{
293
+ if ($ this ->options ['directory_conflict_behavior ' ] == static ::CONFLICT_BEHAVIOR_IGNORE && $ this ->directoryExists ($ path )) {
294
+ return ;
295
+ }
296
+
279
297
$ newDirPathArray = explode ('/ ' , $ path );
280
298
$ newDirName = array_pop ($ newDirPathArray );
281
299
$ path = implode ('/ ' , $ newDirPathArray );
0 commit comments