Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2279: File permissions are kept upon save #2281

Merged
merged 1 commit into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project **does not** adhere to [Semantic Versioning](http://semver.org/).
This file tries to follow the conventions proposed by [keepachangelog.com](http://keepachangelog.com/).
Here, the categories "Changed" for added and changed functionality,
"Fixed" for fixed functionality, and
"Removed" for removed functionality is used.
"Removed" for removed functionality are used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "are"?
Functionality is singular
Either you let the is or you use functionalities

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the object is "categories" which is plural.


We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#NUM`.

Expand All @@ -14,6 +14,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
### Changed

### Fixed
- We fixed an issue where the file permissions of the .bib-file were changed upon saving [#2279](https://github.com/JabRef/jabref/issues/2279).

### Removed

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.EnumSet;
import java.util.Set;

import net.sf.jabref.logic.util.io.FileBasedLock;
import net.sf.jabref.logic.util.io.FileUtil;
Expand Down Expand Up @@ -83,7 +86,24 @@ public void commit(Path file) throws SaveException {
LOGGER.error("Error when creating lock file.", ex);
}

// Try to save file permissions to restore them later (by default: allow everything)
Set<PosixFilePermission> oldFilePermissions = EnumSet.allOf(PosixFilePermission.class);
if (Files.exists(file)) {
try {
oldFilePermissions = Files.getPosixFilePermissions(file);
} catch (IOException exception) {
LOGGER.warn("Error getting file permissions.", exception);
}
}

FileUtil.copyFile(temporaryFile, file, true);

// Restore file permissions
try {
Files.setPosixFilePermissions(file, oldFilePermissions);
} catch (IOException exception) {
throw new SaveException(exception);
}
} finally {
FileBasedLock.deleteLockFile(file);
}
Expand Down