Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SR2-projet2-VANDEWAETER-DIAF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabio Vandewaeter
SR2-projet2-VANDEWAETER-DIAF
Commits
7de264ef
Commit
7de264ef
authored
3 weeks ago
by
Fabio Vandewaeter
Browse files
Options
Downloads
Patches
Plain Diff
synchro fonctionne quand dossier local vide
parent
1e5b179b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/main/java/fil/sr2/projet2/FlopBoxClient.java
+206
-84
206 additions, 84 deletions
src/main/java/fil/sr2/projet2/FlopBoxClient.java
with
207 additions
and
84 deletions
.gitignore
+
1
−
0
View file @
7de264ef
target/
flopbox-sync/
This diff is collapsed.
Click to expand it.
src/main/java/fil/sr2/projet2/FlopBoxClient.java
+
206
−
84
View file @
7de264ef
...
...
@@ -235,46 +235,89 @@ public class FlopBoxClient {
*/
public
void
importFiles
(
String
alias
,
String
remotePath
,
JsonNode
tree
,
Path
localDir
)
throws
IOException
,
InterruptedException
{
/*
* if (!filesMetadata.containsKey(alias)) {
* filesMetadata.put(alias, new HashMap<>());
* }
*
* // Traitement des dossiers
* if (tree.has("children") && tree.get("children").isArray()) {
* for (JsonNode dir : tree.get("children")) {
* String dirName = dir.get("name").asText();
* String newRemotePath = remotePath.isEmpty() ? dirName : remotePath + "/" +
* dirName;
* Path newLocalDir = localDir.resolve(dirName);
*
* Files.createDirectories(newLocalDir);
*
* // Récupération récursive du contenu du dossier
* JsonNode subTree = fetchFtpTree(alias, newRemotePath);
* importFiles(alias, newRemotePath, subTree, newLocalDir);
* }
* }
*
* // Traitement des fichiers
* if (tree.has("files") && tree.get("files").isArray()) {
* for (JsonNode file : tree.get("files")) {
* String fileName = file.get("name").asText();
* String fileRemotePath = remotePath.isEmpty() ? fileName : remotePath + "/" +
* fileName;
* Path localFile = localDir.resolve(fileName);
*
* // Skip .deleted directory files at root level
* if (fileRemotePath.startsWith(".deleted/")) {
* continue;
* }
*
* // Téléchargement du fichier
* downloadFile(alias, fileRemotePath, localFile);
*
* // Stockage des métadonnées
* long fileSize = Files.size(localFile);
* long lastModified = Files.getLastModifiedTime(localFile).toMillis();
*
* FileInfo fileInfo = new FileInfo(fileRemotePath, fileSize, lastModified);
* filesMetadata.get(alias).put(fileRemotePath, fileInfo);
* }
* }
*/
if
(!
filesMetadata
.
containsKey
(
alias
))
{
filesMetadata
.
put
(
alias
,
new
HashMap
<>());
}
// Traitement des
doss
iers
// Traitement des
éléments dans 'children' (répertoires et fich
iers
)
if
(
tree
.
has
(
"children"
)
&&
tree
.
get
(
"children"
).
isArray
())
{
for
(
JsonNode
dir
:
tree
.
get
(
"children"
))
{
String
dirName
=
dir
.
get
(
"name"
).
asText
();
String
newRemotePath
=
remotePath
.
isEmpty
()
?
dirName
:
remotePath
+
"/"
+
dirName
;
Path
newLocalDir
=
localDir
.
resolve
(
dirName
);
for
(
JsonNode
child
:
tree
.
get
(
"children"
))
{
String
childName
=
child
.
get
(
"name"
).
asText
();
boolean
isDirectory
=
child
.
get
(
"isDirectory"
).
asBoolean
();
String
newRemotePath
=
remotePath
.
isEmpty
()
?
childName
:
remotePath
+
"/"
+
childName
;
Path
newLocalDir
=
localDir
.
resolve
(
childName
);
if
(
isDirectory
)
{
// Si c'est un répertoire, on le crée et on appelle récursivement pour son
// contenu
Files
.
createDirectories
(
newLocalDir
);
JsonNode
subTree
=
fetchFtpTree
(
alias
,
newRemotePath
);
importFiles
(
alias
,
newRemotePath
,
subTree
,
newLocalDir
);
}
else
{
// Si c'est un fichier, on le télécharge
Path
localFile
=
newLocalDir
;
// Skip .deleted directory files at root level
if
(
newRemotePath
.
startsWith
(
".deleted/"
))
{
continue
;
}
Files
.
createDirectories
(
newLocalDir
);
// Téléchargement du fichier
downloadFile
(
alias
,
newRemotePath
,
localFile
);
// Récupération récursive du contenu du dossier
JsonNode
subTree
=
fetchFtpTree
(
alias
,
newRemotePath
);
importFiles
(
alias
,
newRemotePath
,
subTree
,
newLocalDir
);
}
}
// Stockage des métadonnées
long
fileSize
=
Files
.
size
(
localFile
);
long
lastModified
=
Files
.
getLastModifiedTime
(
localFile
).
toMillis
();
// Traitement des fichiers
if
(
tree
.
has
(
"files"
)
&&
tree
.
get
(
"files"
).
isArray
())
{
for
(
JsonNode
file
:
tree
.
get
(
"files"
))
{
String
fileName
=
file
.
get
(
"name"
).
asText
();
String
fileRemotePath
=
remotePath
.
isEmpty
()
?
fileName
:
remotePath
+
"/"
+
fileName
;
Path
localFile
=
localDir
.
resolve
(
fileName
);
// Skip .deleted directory files at root level
if
(
fileRemotePath
.
startsWith
(
".deleted/"
))
{
continue
;
FileInfo
fileInfo
=
new
FileInfo
(
newRemotePath
,
fileSize
,
lastModified
);
filesMetadata
.
get
(
alias
).
put
(
newRemotePath
,
fileInfo
);
}
// Téléchargement du fichier
downloadFile
(
alias
,
fileRemotePath
,
localFile
);
// Stockage des métadonnées
long
fileSize
=
Files
.
size
(
localFile
);
long
lastModified
=
Files
.
getLastModifiedTime
(
localFile
).
toMillis
();
FileInfo
fileInfo
=
new
FileInfo
(
fileRemotePath
,
fileSize
,
lastModified
);
filesMetadata
.
get
(
alias
).
put
(
fileRemotePath
,
fileInfo
);
}
}
}
...
...
@@ -430,6 +473,89 @@ public class FlopBoxClient {
* @throws InterruptedException En cas d'interruption lors de la vérification
*/
public
void
checkRemoteChanges
(
String
alias
,
String
remotePath
)
throws
IOException
,
InterruptedException
{
/*
* JsonNode tree = fetchFtpTree(alias, remotePath);
* Path localDir = syncDirectory.resolve(alias);
*
* if (!remotePath.isEmpty()) {
* localDir = localDir.resolve(remotePath);
* }
*
* // Traitement des dossiers
* if (tree.has("children") && tree.get("children").isArray()) {
* for (JsonNode dir : tree.get("children")) {
* String dirName = dir.get("name").asText();
*
* // Skip .deleted directory
* if (dirName.equals(".deleted") && remotePath.isEmpty()) {
* continue;
* }
*
* String newRemotePath = remotePath.isEmpty() ? dirName : remotePath + "/" +
* dirName;
* Path newLocalDir = localDir.resolve(dirName);
*
* Files.createDirectories(newLocalDir);
*
* // Récursion pour les sous-répertoires
* checkRemoteChanges(alias, newRemotePath);
* }
* }
*
* // Traitement des fichiers
* if (tree.has("files") && tree.get("files").isArray()) {
* for (JsonNode file : tree.get("files")) {
* String fileName = file.get("name").asText();
* String fileRemotePath = remotePath.isEmpty() ? fileName : remotePath + "/" +
* fileName;
* Path localFile = localDir.resolve(fileName);
*
* long remoteSize = file.get("size").asLong();
* long remoteModified = 0;
*
* if (file.has("timestamp")) {
* remoteModified = file.get("timestamp").asLong();
* }
*
* Map<String, FileInfo> aliasMetadata = filesMetadata.getOrDefault(alias, new
* HashMap<>());
* FileInfo storedInfo = aliasMetadata.get(fileRemotePath);
*
* boolean needDownload = false;
*
* if (!Files.exists(localFile)) {
* // Fichier distant non présent localement
* needDownload = true;
* } else if (storedInfo == null) {
* // Pas d'information stockée pour ce fichier
* needDownload = true;
* } else if (remoteModified > 0 && remoteModified > storedInfo.lastModified) {
* // Fichier distant plus récent
* needDownload = true;
* } else if (remoteSize != storedInfo.size) {
* // Taille différente
* needDownload = true;
* }
*
* if (needDownload) {
* downloadFile(alias, fileRemotePath, localFile);
*
* // Mise à jour des métadonnées
* long actualSize = Files.size(localFile);
* long actualLastModified = Files.getLastModifiedTime(localFile).toMillis();
*
* if (!aliasMetadata.containsKey(fileRemotePath)) {
* aliasMetadata.put(fileRemotePath, new FileInfo(fileRemotePath, actualSize,
* actualLastModified));
* } else {
* storedInfo.size = actualSize;
* storedInfo.lastModified = actualLastModified;
* }
* }
* }
* }
*/
JsonNode
tree
=
fetchFtpTree
(
alias
,
remotePath
);
Path
localDir
=
syncDirectory
.
resolve
(
alias
);
...
...
@@ -437,71 +563,67 @@ public class FlopBoxClient {
localDir
=
localDir
.
resolve
(
remotePath
);
}
// Traitement des
doss
iers
// Traitement des
éléments dans 'children' (répertoires et fich
iers
)
if
(
tree
.
has
(
"children"
)
&&
tree
.
get
(
"children"
).
isArray
())
{
for
(
JsonNode
dir
:
tree
.
get
(
"children"
))
{
String
dirName
=
dir
.
get
(
"name"
).
asText
();
for
(
JsonNode
child
:
tree
.
get
(
"children"
))
{
String
childName
=
child
.
get
(
"name"
).
asText
();
boolean
isDirectory
=
child
.
get
(
"isDirectory"
).
asBoolean
();
// Skip .deleted directory
if
(
dir
Name
.
equals
(
".deleted"
)
&&
remotePath
.
isEmpty
())
{
if
(
child
Name
.
equals
(
".deleted"
)
&&
remotePath
.
isEmpty
())
{
continue
;
}
String
newRemotePath
=
remotePath
.
isEmpty
()
?
dirName
:
remotePath
+
"/"
+
dirName
;
Path
newLocalDir
=
localDir
.
resolve
(
dirName
);
Files
.
createDirectories
(
newLocalDir
);
// Récursion pour les sous-répertoires
checkRemoteChanges
(
alias
,
newRemotePath
);
}
}
String
newRemotePath
=
remotePath
.
isEmpty
()
?
childName
:
remotePath
+
"/"
+
childName
;
Path
newLocalDir
=
localDir
.
resolve
(
childName
);
if
(
isDirectory
)
{
Files
.
createDirectories
(
newLocalDir
);
// Récursion pour les sous-répertoires
checkRemoteChanges
(
alias
,
newRemotePath
);
}
else
{
// Traitement des fichiers
Path
localFile
=
newLocalDir
;
long
remoteSize
=
child
.
get
(
"size"
).
asLong
();
long
remoteModified
=
0
;
if
(
child
.
has
(
"timestamp"
))
{
remoteModified
=
child
.
get
(
"timestamp"
).
asLong
();
}
// Traitement des fichiers
if
(
tree
.
has
(
"files"
)
&&
tree
.
get
(
"files"
).
isArray
())
{
for
(
JsonNode
file
:
tree
.
get
(
"files"
))
{
String
fileName
=
file
.
get
(
"name"
).
asText
();
String
fileRemotePath
=
remotePath
.
isEmpty
()
?
fileName
:
remotePath
+
"/"
+
fileName
;
Path
localFile
=
localDir
.
resolve
(
fileName
);
Map
<
String
,
FileInfo
>
aliasMetadata
=
filesMetadata
.
getOrDefault
(
alias
,
new
HashMap
<>());
FileInfo
storedInfo
=
aliasMetadata
.
get
(
newRemotePath
);
long
remoteSize
=
file
.
get
(
"size"
).
asLong
();
long
remoteModified
=
0
;
boolean
needDownload
=
false
;
if
(
file
.
has
(
"timestamp"
))
{
remoteModified
=
file
.
get
(
"timestamp"
).
asLong
();
}
Map
<
String
,
FileInfo
>
aliasMetadata
=
filesMetadata
.
getOrDefault
(
alias
,
new
HashMap
<>());
FileInfo
storedInfo
=
aliasMetadata
.
get
(
fileRemotePath
);
boolean
needDownload
=
false
;
if
(!
Files
.
exists
(
localFile
))
{
// Fichier distant non présent localement
needDownload
=
true
;
}
else
if
(
storedInfo
==
null
)
{
// Pas d'information stockée pour ce fichier
needDownload
=
true
;
}
else
if
(
remoteModified
>
0
&&
remoteModified
>
storedInfo
.
lastModified
)
{
// Fichier distant plus récent
needDownload
=
true
;
}
else
if
(
remoteSize
!=
storedInfo
.
size
)
{
// Taille différente
needDownload
=
true
;
}
if
(!
Files
.
exists
(
localFile
))
{
// Fichier distant non présent localement
needDownload
=
true
;
}
else
if
(
storedInfo
==
null
)
{
// Pas d'information stockée pour ce fichier
needDownload
=
true
;
}
else
if
(
remoteModified
>
0
&&
remoteModified
>
storedInfo
.
lastModified
)
{
// Fichier distant plus récent
needDownload
=
true
;
}
else
if
(
remoteSize
!=
storedInfo
.
size
)
{
// Taille différente
needDownload
=
true
;
}
if
(
needDownload
)
{
downloadFile
(
alias
,
file
RemotePath
,
localFile
);
if
(
needDownload
)
{
downloadFile
(
alias
,
new
RemotePath
,
localFile
);
// Mise à jour des métadonnées
long
actualSize
=
Files
.
size
(
localFile
);
long
actualLastModified
=
Files
.
getLastModifiedTime
(
localFile
).
toMillis
();
// Mise à jour des métadonnées
long
actualSize
=
Files
.
size
(
localFile
);
long
actualLastModified
=
Files
.
getLastModifiedTime
(
localFile
).
toMillis
();
if
(!
aliasMetadata
.
containsKey
(
fileRemotePath
))
{
aliasMetadata
.
put
(
fileRemotePath
,
new
FileInfo
(
fileRemotePath
,
actualSize
,
actualLastModified
));
}
else
{
storedInfo
.
size
=
actualSize
;
storedInfo
.
lastModified
=
actualLastModified
;
if
(!
aliasMetadata
.
containsKey
(
newRemotePath
))
{
aliasMetadata
.
put
(
newRemotePath
,
new
FileInfo
(
newRemotePath
,
actualSize
,
actualLastModified
));
}
else
{
storedInfo
.
size
=
actualSize
;
storedInfo
.
lastModified
=
actualLastModified
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment