Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Add default .syignore to sync folders when doing 'sy init'; resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Mar 29, 2015
1 parent a70a268 commit 3d07fff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Map;
import java.util.logging.Level;

Expand Down Expand Up @@ -58,6 +60,8 @@
* @author Philipp C. Heckel <philipp.heckel@gmail.com>
*/
public class InitOperation extends AbstractInitOperation {
public static final String DEFAULT_IGNORE_FILE = "/" + InitOperation.class.getPackage().getName().replace('.', '/') + "/default.syignore";

private InitOperationOptions options;
private InitOperationResult result;

Expand Down Expand Up @@ -104,7 +108,7 @@ public InitOperationResult execute() throws Exception {
File appDir = createAppDirs(options.getLocalDir()); // TODO [medium] create temp dir first, ask password cannot be done after
File configFile = new File(appDir, Config.FILE_CONFIG);
File repoFile = new File(appDir, Config.FILE_REPO);
File masterFile = new File(appDir, Config.FILE_MASTER);
File masterFile = new File(appDir, Config.FILE_MASTER);

// Save config.xml and repo file
saveLocalConfig(configFile, repoFile, masterFile, masterKeyPassword);
Expand All @@ -118,6 +122,7 @@ public InitOperationResult execute() throws Exception {

// Add to daemon (if requested)
addToDaemonIfEnabled();
createDefaultIgnoreFile();

// Make link
GenlinkOperationResult genlinkOperationResult = generateLink(options.getConfigTO());
Expand All @@ -128,6 +133,20 @@ public InitOperationResult execute() throws Exception {
return result;
}

private void createDefaultIgnoreFile() throws IOException {
try {
File ignoreFile = new File(options.getLocalDir(), Config.FILE_IGNORE);

logger.log(Level.INFO, "Creating default .syignore file at " + ignoreFile + " ...");

InputStream defaultConfigFileinputStream = InitOperation.class.getResourceAsStream(DEFAULT_IGNORE_FILE);
Files.copy(defaultConfigFileinputStream, ignoreFile.toPath());
}
catch (IOException e) {
logger.log(Level.WARNING, "Error creating default .syignore file. IGNORING.", e);
}
}

private void saveLocalConfig(File configFile, File repoFile, File masterFile, String masterKeyPassword) throws Exception {
if (options.isEncryptionEnabled()) {
SaltedSecretKey masterKey = createMasterKeyFromPassword(masterKeyPassword); // This takes looong!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*.filepart
*~
*.part
*.crdownload
*.unison*
*.csync_timedif.ctmp*
.csync_*
.*.sw?
.*.*sw?
.csync-progressdatabase
.DS_Store
.ds_store
._*
Thumbs.db
thumbs.db
desktop.ini
*.kate-swp
*_conflict-*
*.~*
.TermporaryItems
.Trashes
.DocumentRevisions-V100
.fseventd
.apdisk
~$*
.~lock.*

0 comments on commit 3d07fff

Please sign in to comment.