← Back to team overview

syncany-team team mailing list archive

[Bug 993815] [NEW] Changing version bug

 

Public bug reported:


Hi,

I found another error in databasehelper.java.
The error is produced by the wrong use of referencial and copy value objects.

In funtion public CloneFile createFile(Profile profile, Update update,
SyncStatus syncStatus):

databasehelper.java
...
// Chunks from previous version
        if (update.getVersion() > 1) {
            CloneFile previousVersion = getFileOrFolder(profile, update.getFileId(), update.getVersion() - 1);
            
            if (previousVersion != null) {            
                newFile.setChunks(previousVersion.getChunks());
            }
            else {
                if (logger.isLoggable(Level.WARNING)) {
                    logger.log(Level.WARNING, "Could not find previous version for file {0} in database.", newFile);
                }
            }           
        }

when do the newFile.setChunks this copy the reference of chunk's list
and after when remplace the chunks replace the chunks of current version
and before version.

clonefile.java
...
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = chunks;
    }

    public void setChunk(int index, CloneChunk chunk) {
        chunks.set(index, chunk);
    }


databasehelper.java
...
        // Chunks changed
        if (!update.getChunksChanged().isEmpty()) {
            for (Map.Entry<Integer, Long> entry : update.getChunksChanged().entrySet()) {
                int chunkIndex = entry.getKey();
                long chunkId = entry.getValue();

                em.getTransaction().begin();

                CloneChunk chunk = getChunk(chunkId, true);

                em.merge(chunk);
                em.flush();
                em.getTransaction().commit();

                newFile.setChunk(chunkIndex, chunk);
            }
        }


To solve this I do some changes in the file clonefile.java:

clonefile.java
...
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = new ArrayList<CloneChunk>(chunks);
    }

    public void setChunk(int index, CloneChunk chunk) {
        chunks.remove(index);
        chunks.add(index, chunk);
    }

And now the chunks list of any version are copy and not reference.

Regards!

** Affects: syncany
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Syncany
Team, which is subscribed to Syncany.
https://bugs.launchpad.net/bugs/993815

Title:
  Changing version bug

Status in Syncany:
  New

Bug description:
  
  Hi,

  I found another error in databasehelper.java.
  The error is produced by the wrong use of referencial and copy value objects.

  In funtion public CloneFile createFile(Profile profile, Update update,
  SyncStatus syncStatus):

  databasehelper.java
  ...
  // Chunks from previous version
          if (update.getVersion() > 1) {
              CloneFile previousVersion = getFileOrFolder(profile, update.getFileId(), update.getVersion() - 1);
              
              if (previousVersion != null) {            
                  newFile.setChunks(previousVersion.getChunks());
              }
              else {
                  if (logger.isLoggable(Level.WARNING)) {
                      logger.log(Level.WARNING, "Could not find previous version for file {0} in database.", newFile);
                  }
              }           
          }

  when do the newFile.setChunks this copy the reference of chunk's list
  and after when remplace the chunks replace the chunks of current
  version and before version.

  clonefile.java
  ...
      public void setChunks(List<CloneChunk> chunks) {
          this.chunks = chunks;
      }

      public void setChunk(int index, CloneChunk chunk) {
          chunks.set(index, chunk);
      }


  databasehelper.java
  ...
          // Chunks changed
          if (!update.getChunksChanged().isEmpty()) {
              for (Map.Entry<Integer, Long> entry : update.getChunksChanged().entrySet()) {
                  int chunkIndex = entry.getKey();
                  long chunkId = entry.getValue();

                  em.getTransaction().begin();

                  CloneChunk chunk = getChunk(chunkId, true);

                  em.merge(chunk);
                  em.flush();
                  em.getTransaction().commit();

                  newFile.setChunk(chunkIndex, chunk);
              }
          }

  
  To solve this I do some changes in the file clonefile.java:

  clonefile.java
  ...
      public void setChunks(List<CloneChunk> chunks) {
          this.chunks = new ArrayList<CloneChunk>(chunks);
      }

      public void setChunk(int index, CloneChunk chunk) {
          chunks.remove(index);
          chunks.add(index, chunk);
      }

  And now the chunks list of any version are copy and not reference.

  Regards!

To manage notifications about this bug go to:
https://bugs.launchpad.net/syncany/+bug/993815/+subscriptions


Follow ups

References