Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

allprojects {
group = 'com.spectralogic.ds3'
version = '3.2.11'
version = '3.2.12'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import com.google.common.collect.ImmutableList;
import com.spectralogic.ds3client.metadata.jna.Advapi32;
import com.spectralogic.ds3client.networking.Metadata;
import com.spectralogic.ds3client.utils.Guard;
import com.sun.jna.platform.win32.WinNT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
Expand All @@ -36,6 +40,9 @@
import static com.spectralogic.ds3client.metadata.MetadataKeyConstants.KEY_OWNER;

class WindowsMetadataRestore extends AbstractMetadataRestore {

private static final Logger LOG = LoggerFactory.getLogger(WindowsMetadataRestore.class);

WindowsMetadataRestore(final Metadata metadata, final String filePath, final String localOS) {
this.metadata = metadata;
this.objectName = filePath;
Expand All @@ -44,26 +51,31 @@ class WindowsMetadataRestore extends AbstractMetadataRestore {

@Override
public void restoreUserAndOwner() throws IOException {
if (storedOS.equals(localOS)) {
String ownerSid = null;
if (metadata.get(KEY_OWNER).size() > 0) {
ownerSid = metadata.get(KEY_OWNER).get(0);
}
String groupSid = null;
if (metadata.get(KEY_GROUP).size() > 0) {
groupSid = metadata.get(KEY_GROUP).get(0);
}
if (ownerSid != null && groupSid != null && !ownerSid.equals("") && !groupSid.equals("")) {
setOwnerIdandGroupId(ownerSid, groupSid);
if (storedOS != null && storedOS.equals(localOS)) {

final String ownerSid = getMetadataProperty(metadata, KEY_OWNER);
final String groupSid = getMetadataProperty(metadata, KEY_GROUP);

if (!Guard.isStringNullOrEmpty(ownerSid) && !Guard.isStringNullOrEmpty(groupSid)) {
setOwnerIdAndGroupId(ownerSid, groupSid);
} else {
LOG.warn("Cannot determine owner or group settings for {}", this.objectName);
}
} else {
LOG.warn("The OS settings for owner and group properties cannot be restored for {}", this.objectName);
}
}

private static String getMetadataProperty(final Metadata metadata, final String metadataName) {
return metadata.get(metadataName).get(0);
}

@Override
public void restorePermissions() throws IOException, InterruptedException {
if (storedOS != null && storedOS.equals(localOS)) {
setPermissionsForWindows();
} else {
LOG.warn("The OS settings for the file permissions cannot be restored for {}", this.objectName);
}
restoreFlags();
}
Expand All @@ -76,19 +88,26 @@ private void setPermissionsForWindows() throws IOException {
final String userListDisplay;
final String[] users;
final String[] usersDisplay;
if (metadata.get("ds3-userList").size() > 0) {
if (Guard.isNotNullAndNotEmpty(metadata.get("ds3-userList"))) {
userList = metadata.get("ds3-userList").get(0);
if (metadata.get("ds3-userListDisplay").size() > 0) {
if (Guard.isNotNullAndNotEmpty(metadata.get("ds3-userListDisplay"))) {
userListDisplay = metadata.get("ds3-userListDisplay").get(0);
users = userList.split("-");
usersDisplay = userListDisplay.split("-");
for (int i = 0; i < users.length; i++) {
if (metadata.get("ds3-" + users[i]).size() > 0) {
final String ownerPermission = metadata.get("ds3-" + users[i]).get(0);
final String user = users[i];
if (Guard.isNotNullAndNotEmpty(metadata.get("ds3-" + user))) {
final String ownerPermission = metadata.get("ds3-" + user).get(0);
restorePermissionByUser(ownerPermission, usersDisplay[i], aclEntryBuilder);
} else {
LOG.warn("Did not find any permissions for {} for file {}", user, this.objectName);
}
}
} else {
LOG.warn("There was not a 'userListDisplay' metadata entry for file {}, so we will not restore any permissions", this.objectName);
}
} else {
LOG.warn("There was not a 'userList' metadata entry for file {}, so we will not restore any permissions", this.objectName);
}

aclAttributeView.setAcl(aclEntryBuilder.build());
Expand Down Expand Up @@ -148,7 +167,7 @@ private void restorePermissionByUser(final String permission,
* @param ownerSidId sid of the owner
* @param groupSidId sid of the group
*/
private void setOwnerIdandGroupId(final String ownerSidId, final String groupSidId) throws IOException {
private void setOwnerIdAndGroupId(final String ownerSidId, final String groupSidId) throws IOException {
final int infoType = WinNT.OWNER_SECURITY_INFORMATION | WinNT.GROUP_SECURITY_INFORMATION;
final WinNT.PSIDByReference referenceOwner = new WinNT.PSIDByReference();
Advapi32.INSTANCE.ConvertStringSidToSid(ownerSidId, referenceOwner);
Expand All @@ -166,7 +185,11 @@ private void restoreFlags() throws IOException, InterruptedException {
if (metadata.get(KEY_FLAGS).size() > 0) {
final String flags = metadata.get(KEY_FLAGS).get(0);
restoreFlagsWindows(flags);
} else {
LOG.warn("The file flag settings do not exist for file {} and will not be restored", this.objectName);
}
} else {
LOG.warn("The OS settings for restoring the file flags cannot be done for {}", this.objectName);
}
}

Expand Down Expand Up @@ -199,9 +222,12 @@ private void restoreFlagsWindows(final String flag) throws IOException, Interrup
stringBuilder.append(" -I");
stringBuilder.append(" -H");
}
stringBuilder.append(" " + "\"" + objectName + "\"");
stringBuilder.append(" " + "\"").append(objectName).append("\"");

final Process p = Runtime.getRuntime().exec(stringBuilder.toString().split(" "));
p.waitFor();
final int returnCode = p.waitFor();
if (returnCode != 0) {
LOG.error("Restoring the flag settings for file {} was not successful", this.objectName);
}
}
}